You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/content/docs/basics.adoc
+66-14Lines changed: 66 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,8 +75,12 @@ NOTE: if you don't already have layouts and partials in your project, <<install-
75
75
76
76
If you’re using a theme, you can take advantage of its layouts, but you’re also free to add your own. Layouts are built on a powerful inheritance system, allowing flexibility and customization.
TIP: When using a theme, you can create new layouts that extend the existing theme layouts or partially override them to better suit your needs. Learn more here: xref:advanced.adoc#overriding-theme[Overriding Theme].
79
82
83
+
80
84
In this sample we will create a simple 3 steps inheritance layout. All below files should be located in the `templates/layouts/` directory.
81
85
82
86
To do so, you will first need a `default.html` file as followed:
@@ -255,7 +259,7 @@ TIP: There are different ways to link your pages as explained in the link:{site
255
259
256
260
You can use Qute to access site and pages data. For this use the `site` and `page` variables:
257
261
258
-
* The `site` (link:{roqjavadocmodelurl}Site.html[javadoc,window=_blank]) variable allow to access site global info from any page, document, layout or partial.
262
+
* The `site` (link:{roqjavadocmodelurl}model/Site.html[javadoc,window=_blank]) variable allow to access site global info from any page, document, layout or partial.
259
263
+
260
264
.Show attributes
261
265
[%collapsible]
@@ -322,7 +326,7 @@ You can use Qute to access site and pages data. For this use the `site` and `pag
322
326
|===
323
327
====
324
328
325
-
* The `page` (link:{roqjavadocmodelurl}Page.html[javadoc,window=_blank]) variable is available in pages, documents, layouts, and partials. It contains the info for the page it is used from.
329
+
* The `page` (link:{roqjavadocmodelurl}model/Page.html[javadoc,window=_blank]) variable is available in pages, documents, layouts, and partials. It contains the info for the page it is used from.
326
330
+
327
331
.Show attributes
328
332
[%collapsible]
@@ -454,20 +458,68 @@ Can be access with `{cdi:foo.bar}` in any template.
454
458
455
459
== Template Extensions
456
460
457
-
The Qute templating language supports a concept called https://quarkus.io/guides/qute#template-extension-methods[template extension methods]. These methods allow us to add functional to types and expose it in our templates. Moving logic from the template to Java code gives us the ability to use a more robust language for more complex logic and makes the functionality more easily reusable,as well as keeping our templates clean. Roq has several built-in template extensions:
461
+
The Qute templating language supports a concept called https://quarkus.io/guides/qute#template-extension-methods[template extension methods]. These methods allow us to add functional to types and expose it in our templates. Moving logic from the template to Java code gives us the ability to use a more robust language for more complex logic and makes the functionality more easily reusable,as well as keeping our templates clean. Roq has several built-in template extensions (link:{roqjavadocmodelurl}RoqTemplateExtension.html[javadoc,window=_blank]):
458
462
459
-
[%header]
463
+
[cols="1,2", options="header"]
460
464
|===
461
-
| Method Name | Parent Type | Return Type | Parameters | Description
462
-
| `asStrings` | `String` or `JsonArray` | `List<String` | | Returns a list of `String`s created by splitting the provided `String`, or converting the `JsonArray` to a `List`. An empty `List` is returned for objects of other types.
463
-
| `collection` | `RoqCollections` | `RoqCollection`| `String key`| Returns the `RoqCollection` for `key`
464
-
| `contentAbstract` | `Page` or `String` | `String` | `int limit` | Returns an abstract for the given `Page` or HTML content. A `Page` is rendered to HTML first, then all HTML is stripped away (see `stripHtml`) and the first `limit` words (default: 75) are returned.
465
-
| `mimeType` | `String` | `String` | | Returns the mimetype for the specified file. A `null` is returned for unrecognized or invalid file names/types.
466
-
| `numberOfWords` | `String` | `long` | | Returns the number of words in the given String
467
-
| `readTime` | `Page` | `long` | | Returns the estimated number of minutes to read the given page
468
-
| `slugify` | `String` | `String` | | Applies Roq's slug formatting to the given string
469
-
| `stripHtml` | `String` | `String` | | Strips all HTML tags from the given string, returning plain text
470
-
| `wordLimit` | `String` | `String` | `int limit` | Returns the first `limit` words in the given text.
465
+
| Usage in a Qute template | Description
466
+
467
+
| ``text.numberOfWords``
468
+
| Returns the number of words in the string
469
+
470
+
| ``text.wordLimit(limit)``
471
+
| Returns the text limited to `limit` words, adds "..." if truncated
472
+
473
+
| ``text.slugify``
474
+
| Returns a slugified version of the text
475
+
476
+
| ``htmlContent.contentAbstract(limit)``
477
+
| Returns the HTML content limited to `limit` words
478
+
479
+
| ``htmlContent.stripHtml``
480
+
| Returns the text with all HTML tags removed
481
+
482
+
| ``page.readTime``
483
+
| Returns the estimated reading time in minutes for the page content
484
+
485
+
| ``page.contentAbstract``
486
+
| Returns the first 75 words of the page content
487
+
488
+
| ``page.contentAbstract(limit)``
489
+
| Returns the page content limited to `limit` words
490
+
491
+
| ``list.limit(n)``
492
+
| Returns only the first `n` items of the list
493
+
494
+
| ``list.randomise``
495
+
| Returns the list in random order
496
+
497
+
| ``list.reverse``
498
+
| Returns the list in reverse order
499
+
500
+
| ``collections.collection(key)``
501
+
| Returns the collection for the given key
502
+
503
+
| ``posts.filter(key, value)``
504
+
| Returns only documents matching the front-matter key/value
505
+
506
+
| ``posts.future``
507
+
| Returns only documents dated in the future
508
+
509
+
| ``posts.past``
510
+
| Returns only documents dated in the past
511
+
512
+
| ``posts.sortBy(key, reverse)``
513
+
| Sorts documents by a front-matter key (string), optionally reversed
514
+
515
+
| ``posts.sortByDate(reverse)``
516
+
| Sorts documents by date, optionally reversed
517
+
518
+
| ``field.asStrings``
519
+
| Normalizes a front-matter field into a list of strings
520
+
521
+
| ``fileName.mimeType``
522
+
| Returns the MIME type based on the file name extension
471
523
|===
472
524
473
525
You can provide your own template extensions by adding a class to your projects `src/main/java` directory and annotating either class or the `public static` method with `@TemplateExtension`:
0 commit comments