### Example Tag Call and Rendered Output Source: https://quarkus.io/guides/qute-reference Shows an example call to a user tag with named and unnamed arguments, and the resulting rendered output. ```html {#test 'Martin' readonly=true /} ``` ```text Martin true readonly="true" ``` -------------------------------- ### Localized File Example Source: https://quarkus.io/guides/qute-reference Example of a localized message bundle file for the German locale. This approach is convenient for managing localized strings externally. ```properties # Example for msg_de.properties hello_name=Hallo {name}! ``` -------------------------------- ### Virtual Method with Java Class Example Source: https://quarkus.io/guides/qute-reference Example of a Java class that could back a virtual method resolver. ```java class Item { String buildName(String name, int age) { return name + ":" + age; } } ``` -------------------------------- ### Qute Tag Examples Source: https://quarkus.io/guides/qute-reference Demonstrates various tag syntaxes and whether they are parsed or ignored by the Qute parser. ```html {_foo.bar} __**(1)** {! comment !}__**(2)** { foo} __**(3)** {{foo}} __**(4)** {"foo":true} __**(5)** ``` -------------------------------- ### Template Rendering Discounted Price Source: https://quarkus.io/guides/qute-reference Example of how to render the discounted price using the template extension. ```java {item.discountedPrice} __**(1)** ``` -------------------------------- ### Virtual Method Examples Source: https://quarkus.io/guides/qute-reference Shows how to invoke virtual methods within expressions, including methods with parameters and infix notation for single-parameter methods. ```qute {item.getLabels(1)} __**(1)** {name or 'John'} __**(2)** ``` -------------------------------- ### Property Accessor Examples Source: https://quarkus.io/guides/qute-reference Demonstrates different ways to access properties within an expression, including dot notation, bracket notation, and namespaces. ```qute {name} __**(1)** {item.name} __**(2)** {item['name']} __**(3)** {global:colors} __**(4)** ``` -------------------------------- ### Curl Request to Render Template Source: https://quarkus.io/guides/qute Example of how to call the REST endpoint to render the 'Hello Qute' template with a query parameter. ```bash $ curl -w "\n" http://localhost:8080/hello?name=Martin ``` -------------------------------- ### Qute Output with Standalone Lines Enabled Source: https://quarkus.io/guides/qute-reference Shows the output of the template example when standalone line removal is disabled via configuration. ```html ``` -------------------------------- ### Qute Default Output Source: https://quarkus.io/guides/qute-reference Shows the output of the template example when standalone lines are removed by default. ```html ``` -------------------------------- ### Various Parameter Declarations Source: https://quarkus.io/guides/qute-reference Examples of different parameter declarations including primitive types, generic types, and default values. ```html {@int pages} ``` ```html {@java.util.List strings} ``` ```html {@java.util.Map numbers} ``` ```html {@java.util.Optional param} ``` ```html {@String name="Quarkus"} ``` -------------------------------- ### Template Rendering with Multiple Parameters Source: https://quarkus.io/guides/qute-reference Example of rendering a BigDecimal with its scale set using the extension method with multiple parameters. ```java {item.discountedPrice.scale(2,mode)} __**(1)** ``` -------------------------------- ### Qute Node Resolution Log Messages Source: https://quarkus.io/guides/qute-reference Example log messages indicating the start and completion of expression resolution in Qute templates. Missing 'completed' messages suggest a potential issue. ```log TRACE [io.qua.qut.nodeResolve] Resolve {name} started: Template hello.html at line 8 TRACE [io.qua.qut.nodeResolve] Resolve {name} completed: Template hello.html at line 8 ``` -------------------------------- ### Literal Base Expression Examples Source: https://quarkus.io/guides/qute-reference Illustrates using literal values (strings, integers) as the base for property accessors or virtual method invocations. Note the special syntax prefix required for top-level output expressions. ```qute {='foo'.toUpperCase} __**(1)** {=1.intValue} __**(2)** {#let name=('foo'.toUpperCase)}{name}{/let} __**(3)** {name.replace('foo'.toUpperCase)} __**(4)** ``` -------------------------------- ### Get List Element by Index Source: https://quarkus.io/guides/qute-reference Retrieve a list element at a specific position using `get(index)` or direct index access. ```qute {list.get(0)} ``` ```qute {list.10} ``` ```qute {list[10]} ``` -------------------------------- ### Qute Standalone Line Removal Example Source: https://quarkus.io/guides/qute-reference Illustrates how standalone lines are handled by default in Qute templates. ```html ``` -------------------------------- ### Looping over Integers with for Source: https://quarkus.io/guides/qute-reference The 'for' loop can iterate over integer values. This example shows iteration up to a 'total' value, accessing metadata like count and parity. ```qute {#for i in total} {i}: ({i_count} {i_indexParity} {i_even})
{/for} ``` -------------------------------- ### Virtual Method Example Source: https://quarkus.io/guides/qute-reference Illustrates a virtual method call within an expression. 'buildName(item.name,5)' is a virtual method that can be resolved by a value resolver. ```html

{item.buildName(item.name,5)}

``` -------------------------------- ### Nested Virtual Method Example Source: https://quarkus.io/guides/qute-reference Shows nested virtual method invocations where the result of one method call is passed as an argument to another. ```html

{item.subtractPrice(item.calculateDiscount(10))}

``` -------------------------------- ### Take First N Elements from List Source: https://quarkus.io/guides/qute-reference Get the first `n` elements from a list using `take(n)`. Throws `IndexOutOfBoundsException` if `n` is out of range. ```qute {#for r in recordsList.take(3)} ``` -------------------------------- ### Get Map Value by Key Source: https://quarkus.io/guides/qute-reference Retrieve a map value by its key using `get(key)`. Use bracket notation for keys that are not legal identifiers. ```qute {map.get('foo')} ``` ```qute {map.myKey} ``` ```qute {map['my key']} ``` -------------------------------- ### Call Type-Safe Fragment from Java Source: https://quarkus.io/guides/qute-reference Illustrates how to invoke a type-safe fragment defined in Qute from a Java class. This example shows rendering a single item using the fragment. ```java class ItemService { String renderItem(Item item) { // this would return something like "
  • Foo
  • " return Templates.items$item(item).render(); } } ``` -------------------------------- ### Access Array Length and Elements Source: https://quarkus.io/guides/qute-reference Get the length of an array using `.length` and access elements by index using dot notation (e.g., `.0`) or bracket notation (e.g., `[1]`). The `get(index)` method is also available. ```qute

    Array of length: {myArray.length}

    ``` ```qute
  • First: {myArray.0}
  • ``` ```qute
  • Second: {myArray[1]}
  • ``` ```qute
  • Third: {myArray.get(2)}
  • ``` -------------------------------- ### Define a User Tag Template Source: https://quarkus.io/guides/qute-reference Example of a Qute tag template 'itemDetail.html' demonstrating conditional rendering, passing the first unnamed parameter via 'it', and injecting nested content. ```html {#if showImage} {it.image} {nested-content} {/if} ``` -------------------------------- ### Qute @TemplateData with Target and BigDecimal setScale Example Source: https://quarkus.io/guides/qute-reference Demonstrates using @TemplateData with a target class (BigDecimal) and accessing its methods like setScale() within a Qute template. ```java @TemplateData(target = BigDecimal.class) @TemplateData class Item { public final BigDecimal price; public Item(BigDecimal price) { this.price = price; } } ``` -------------------------------- ### Rendered Hidden Fragment Example Source: https://quarkus.io/guides/qute-reference This is the rendered output of the template containing hidden fragments, demonstrating how included fragments are displayed. ```html

    My page

    This document contains a lot of information !

    ``` -------------------------------- ### HTML Escaping Example Source: https://quarkus.io/guides/qute-reference Demonstrates how to render unescaped HTML content using the 'raw' property. If 'title' resolves to 'Expressions & Escapes', it will be rendered as 'Expressions & Escapes'. ```html

    {title}

    {paragraph.raw} ``` -------------------------------- ### Get First Element of List Source: https://quarkus.io/guides/qute-reference Retrieve the first element of a list using `first`. Throws `NoSuchElementException` if the list is empty. ```qute {recordsList.first} ``` -------------------------------- ### Localized Interface Example Source: https://quarkus.io/guides/qute-reference Defines a localized message bundle interface for the German locale. Use this when you prefer to keep localized strings within your Java code. ```java import io.quarkus.qute.i18n.Localized; import io.quarkus.qute.i18n.Message; @Localized("de") public interface GermanAppMessages extends AppMessages { @Override @Message("Hallo {name}!") String hello_name(String name); } ``` -------------------------------- ### Customized Template Path with @CheckedTemplate Source: https://quarkus.io/guides/qute-reference Configure a custom template path using @CheckedTemplate with basePath and defaultName. The template path for this example will be items/item-and-order. ```java package org.acme.quarkus.sample; import jakarta.ws.rs.Path; import io.quarkus.qute.TemplateInstance; import io.quarkus.qute.CheckedTemplate; @Path("item") public class ItemResource { @CheckedTemplate(basePath = "items", defaultName = CheckedTemplate.HYPHENATED_ELEMENT_NAME) static class Templates { static native TemplateInstance itemAndOrder(Item item); } } ``` -------------------------------- ### JSON Escaping Example Source: https://quarkus.io/guides/qute-reference Shows default JSON escaping behavior. A value like '\nA12345' for 'valueId' will be rendered as '\nA12345', potentially causing invalid JSON. A value like '\tExpressions \n Escapes' for 'valueName' will be rendered as '\\tExpressions \\n Escapes'. ```json { "id": "{valueId.raw}", "name": "{valueName}" } ``` -------------------------------- ### Call a User-defined Tag Source: https://quarkus.io/guides/qute-reference Example of calling the 'itemDetail' user-defined tag within a loop, passing an 'item' object and enabling 'showImage'. The tag content is injected via '{nested-content}'. ```html ``` -------------------------------- ### Parse and Render a Simple Template Source: https://quarkus.io/guides/qute-reference Demonstrates the basic workflow of parsing template content and rendering it with data. Requires an Engine instance. ```java Engine engine = Engine.builder().addDefaults().build(); Template hello = engine.parse(helloHtmlContent); // Renders

    Hello Jim!

    hello.data("name", "Jim").render(); ``` -------------------------------- ### Get Reversed List Iterator Source: https://quarkus.io/guides/qute-reference Iterate over a list in reverse order using `reversed`. ```qute {#for r in recordsList.reversed} ``` -------------------------------- ### Get Map Size Source: https://quarkus.io/guides/qute-reference Retrieve the number of key-value mappings in a map using `size`. ```qute {map.size} ``` -------------------------------- ### Item Resource with Content Negotiation Source: https://quarkus.io/guides/qute-reference This resource demonstrates content negotiation for templates. Different templates (HTML and plain text) are used based on the client's Accept header. ```java @Path("/detail") class DetailResource { @Inject Template item; @GET @Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN }) public TemplateInstance item() { return item.data("myItem", new Item("Alpha", 1000)); } } ``` -------------------------------- ### Get String Value for Concatenation Source: https://quarkus.io/guides/qute-reference Retrieve the string value of an expression, useful for concatenating with other strings. ```qute {str:['/path/to/'] + fileName} ``` -------------------------------- ### Create Qute Engine Instance Source: https://quarkus.io/guides/qute-reference Shows how to create a standalone Qute Engine instance using its builder. In Quarkus, a preconfigured engine is available via injection. ```java Engine engine = Engine.builder().addDefaults().build(); ``` -------------------------------- ### Hello World Qute Template Source: https://quarkus.io/guides/qute A simple Qute template that displays a greeting. Templates in the 'pub' directory are served automatically via HTTP. ```html

    Hello {http:param('name', 'Quarkus')}!

    ``` -------------------------------- ### Format String with Arguments Source: https://quarkus.io/guides/qute-reference Format a string using `fmt` or `format` with `java.lang.String.format()` and provided arguments. ```qute {myStr.fmt("arg1","arg2")} ``` ```qute {myStr.format(locale,arg1)} ``` -------------------------------- ### Format String with Namespace Source: https://quarkus.io/guides/qute-reference Format a string using `str:fmt` or `str:format` with `java.lang.String.format()` and provided arguments, including locale. ```qute {str:format("Hello %s!",name)} ``` ```qute {str:fmt(locale,'%tA',now)} ``` ```qute {str:fmt('/path/to/%s', fileName)} ``` -------------------------------- ### Get Last Element of List Source: https://quarkus.io/guides/qute-reference Retrieve the last element of a list using `last`. Throws `NoSuchElementException` if the list is empty. ```qute {recordsList.last} ``` -------------------------------- ### Include and Reference Fragments in Qute Templates Source: https://quarkus.io/guides/qute-reference Demonstrates including a fragment from another template using `{#include item$item_aliases}` and referencing a fragment within the same template using `{frg:fullname}`. ```html

    User - {user.name}

    {#fragment fullname} {name} {surname} {/fragment}

    This document contains a detailed info about a user.

    {#include item$item_aliases aliases=user.aliases /} __**(1)**__**(2)** {frg:fullname} is a happy user! __**(3)** ``` -------------------------------- ### Accessing Integer Configuration Properties Source: https://quarkus.io/guides/qute-reference Retrieve configuration values as integers. Supports dynamic property name resolution. ```qute {config:integer('quarkus.foo')} ``` ```qute {config:integer(foo.getPropertyName())} ``` -------------------------------- ### Render Template with Data Source: https://quarkus.io/guides/qute-reference Creates a template instance, sets data, and renders the output synchronously. Asynchronous rendering options are also available. ```java hello.data("name", "Jim").render(); ``` -------------------------------- ### Infix Notation for Virtual Method Source: https://quarkus.io/guides/qute-reference Demonstrates calling a virtual method with a single parameter using infix notation. '{item.price or 5}' is translated to 'item.price.or(5)'. ```html

    {item.price or 5}

    ``` -------------------------------- ### Simple Qute Template Source: https://quarkus.io/guides/qute A basic Qute template file with a value expression. ```text Hello {name}! __**(1)** ``` -------------------------------- ### If Section with Operators Source: https://quarkus.io/guides/qute-reference Demonstrates various operators for conditional logic, including logical complement, comparison operators (>, >=, <, <=, ==, !=), and logical operators (&&, ||). ```qute {#if item.age > 43}This item is very old.{/if} ``` ```qute {#if item.price >= 100}This item is expensive.{/if} ``` ```qute {#if item.price < 100}This item is cheap.{/if} ``` ```qute {#if item.age <= 43}This item is young.{/if} ``` ```qute {#if item.name eq 'Foo'}Foo item!{/if} ``` ```qute {#if item.name != 'Bar'}Not a Bar item!{/if} ``` ```qute {#if item.price > 100 && item.isActive}Expensive and active item.{/if} ``` ```qute {#if item.price > 100 || item.isActive}Expensive or active item.{/if} ``` ```qute {#if !item.active}{/if} ``` -------------------------------- ### Configure Qute Engine Builder Source: https://quarkus.io/guides/qute-reference Instantiate a new Qute engine using `Engine.builder()` when using Qute as a standalone library. ```java Engine engine = Engine.builder().build(); ``` -------------------------------- ### Include Another Template with 'include' Section Source: https://quarkus.io/guides/qute-reference Use the 'include' section to embed another template. It can reference data from the current context and optionally accept parameters. ```qute Simple Include {#include foo limit=10 /} __**(1)**__**(2)** ``` -------------------------------- ### Take Last N Elements from List Source: https://quarkus.io/guides/qute-reference Get the last `n` elements from a list using `takeLast(n)`. Throws `IndexOutOfBoundsException` if `n` is out of range. ```qute {#for r in recordsList.takeLast(3)} ``` -------------------------------- ### Render Template with Multi Source: https://quarkus.io/guides/qute-reference Creates a Multi where each item is a chunk of the rendered template. Rendering is re-triggered on each subscriber computation, suitable for streaming output. ```java template.data(foo).createMulti().subscribe().with(buffer:append,buffer::flush); ``` -------------------------------- ### Accessing Configuration Properties Source: https://quarkus.io/guides/qute-reference Retrieve configuration values by property name. Supports direct access, properties with dots in their names, and dynamic property name resolution. ```qute {config:foo} ``` ```qute {config:['property.with.dot.in.name']} ``` ```qute {config:property('quarkus.foo')} ``` ```qute {config:property(foo.getPropertyName())} ``` -------------------------------- ### Multi-line Message Template Source: https://quarkus.io/guides/qute-reference Message templates can span multiple lines by escaping the line terminator with a backslash. Whitespace at the start of the following line is ignored. ```properties hello=Hello \ {name} and \ good morning! ``` -------------------------------- ### Use Namespace Extension Methods Source: https://quarkus.io/guides/qute-reference Invoke custom extension methods using the defined namespace. The first matching method is used for resolution. ```qute {str:format('%s %s!','Hello', 'world')} ``` ```qute {str:reverse('hello')} ``` -------------------------------- ### Basic Key-Value Pair in Properties File Source: https://quarkus.io/guides/qute-reference Each line in a localized file represents a key/value pair. The key must correspond to a method declared on the message bundle interface, and the value is the message template. The .properties suffix is ignored by Qute. ```properties hello_name=Hallo {name}! ``` -------------------------------- ### Define a type-safe message bundle interface Source: https://quarkus.io/guides/qute-reference Example of defining a message bundle interface with a method for a localized string. The `@MessageBundle` annotation denotes the interface, and `@Message` defines the template for the message. ```java import io.quarkus.qute.i18n.Message; import io.quarkus.qute.i18n.MessageBundle; @MessageBundle __**(1)** public interface AppMessages { @Message("Hello {name}!") __**(2)** String hello_name(String name); __**(3)** } ``` -------------------------------- ### Create String Builder Source: https://quarkus.io/guides/qute-reference Create a new string builder using `str:builder` and append strings to it. Supports concatenation with the `+` operator. ```qute {str:builder('Qute').append("is").append("cool!")} ``` ```qute {str:builder('Qute') + "is" + whatisqute + "!"} ``` -------------------------------- ### If Section with Else If and Else Blocks Source: https://quarkus.io/guides/qute-reference Provides alternative rendering paths using {#else if} and {#else} blocks for comprehensive conditional logic. ```qute {#if item.age > 10} This item is very old. {#else if item.age > 5} This item is quite old. {#else if item.age > 2} This item is old. {#else} This item is not old at all! {/if} ``` -------------------------------- ### Add Qute Web Extension (Maven) Source: https://quarkus.io/guides/qute Include the Qute Web extension in your Maven project to serve templates directly via HTTP. ```xml io.quarkiverse.qute.web quarkus-qute-web ``` -------------------------------- ### Define Local Variables with Set Section Source: https://quarkus.io/guides/qute-reference The 'set' section is an alias for the 'let' section, providing an alternative syntax for defining named local variables. ```qute {#set myParent=item.parent price=item.price}

    {myParent.name}

    Price: {price} {/set} ``` -------------------------------- ### Add Qute Web Extension (Gradle) Source: https://quarkus.io/guides/qute Include the Qute Web extension in your Gradle project to serve templates directly via HTTP. ```gradle implementation("io.quarkiverse.qute.web:quarkus-qute-web") ``` -------------------------------- ### Accessing Data Namespace Source: https://quarkus.io/guides/qute-reference Demonstrates how to use the 'data' namespace to access the original data passed to the template instance, especially when keys might be overridden. ```html {item.name} __**(1)**

      {#for item in item.derivedItems} __**(2)**
    • {item.name} __**(3)** is derived from {data:item.name} __**(4)**
    • {/for}
    ``` -------------------------------- ### Take First N Elements from Array Source: https://quarkus.io/guides/qute-reference Use the `take(n)` method to retrieve the first `n` elements of an array. The `it` keyword refers to the current element within the `#each` section. ```qute First two elements: {#each myArray.take(2)}{it}{/each} ``` -------------------------------- ### Referencing message bundles in Qute templates Source: https://quarkus.io/guides/qute-reference Demonstrates how to reference message bundle keys and parameters within Qute templates using the default 'msg' namespace. ```qute {msg:hello_name('Lucie')} __**(1)** __**(2)** __**(3)** {msg:message(myKey,'Lu')} __**(4)** ``` -------------------------------- ### Define a User Tag with Inheritance Source: https://quarkus.io/guides/qute-reference Demonstrates how to define a user tag `myTag` that utilizes template inheritance, allowing parts of the tag content to be overridden. ```html This is {#insert title}my title{/title}! __**(1)** ``` -------------------------------- ### Integer Addition Source: https://quarkus.io/guides/qute-reference Perform addition on integers using `plus` or the `+` operator. ```qute {counter + 1} ``` ```qute {age plus 10} ``` ```qute {age.plus(10)} ``` -------------------------------- ### Accessing Boolean Configuration Properties Source: https://quarkus.io/guides/qute-reference Retrieve configuration values as booleans. Supports dynamic property name resolution and provides a default value if the property is not found or is false. ```qute {config:boolean('quarkus.foo.boolean') ?: 'Not Found'} ``` ```qute {config:boolean(foo.getPropertyName()) ?: 'property is false'} ``` -------------------------------- ### Define Local Variables with Let Section Source: https://quarkus.io/guides/qute-reference The 'let' section allows defining named local variables within a specific scope. Variables are initialized with expressions, literals, or grouped infix notations. ```qute {#let myParent=order.item.parent isActive=false age=10 price=(order.price + 10)} __**(1)**__**(2)**

    {myParent.name}

    Is active: {isActive} Age: {age} Price: {price} {/let} __**(3)** ``` -------------------------------- ### Handling Empty Collections with else Source: https://quarkus.io/guides/qute-reference Use the {#else} block within a loop section to provide content when the iterated collection is empty. ```qute {#for item in items} {item.name} {#else} No items. {/for} ``` -------------------------------- ### Simple Text Template Source: https://quarkus.io/guides/qute A basic text template using a value expression to insert dynamic content. ```txt Hello {name}! ``` -------------------------------- ### Template Inheritance: Base Template with 'insert' Sections Source: https://quarkus.io/guides/qute-reference Define a base template using 'insert' sections for content that can be overridden. Default content can be provided within these sections. ```qute {#insert title}Default Title{/} __**(1)** {#insert}No body!{/} __**(2)** ``` -------------------------------- ### Template Inheritance: Detail Template Extending Base Source: https://quarkus.io/guides/qute-reference Extend a base template using the 'include' section. Override specific parts defined by 'insert' sections using nested blocks. ```qute {#include base} __**(1)** {#title}My Title{/title} __**(2)**
    __**(3)** My body.
    {/include} ``` -------------------------------- ### Render Template with Uni Source: https://quarkus.io/guides/qute-reference Creates a Uni for template rendering. Rendering is triggered each time Uni.subscribe() is called, allowing for reactive consumption of the output. ```java template.data(foo).createUni().subscribe().with(System.out::println); ``` -------------------------------- ### Format Simple Messages with Qute Source: https://quarkus.io/guides/qute-reference Use the Qute.fmt() static methods to format simple messages with positional or named parameters. The builder API allows for more complex formatting requirements, including content type specification and data injection. ```java import io.quarkus.qute.Qute; Qute.fmt("Hello {}!", "Lucy"); // => Hello Lucy! Qute.fmt("Hello {name} {surname ?: 'Default'}!", Map.of("name", "Andy")); // => Hello Andy Default! Qute.fmt("{header}").contentType("text/html").data("header", "

    My header

    ").render(); // <h1>Header</h1> Qute.fmt("I am {#if ok}happy{#else}sad{/if}!", Map.of("ok", true)); // => I am happy! ``` -------------------------------- ### Configure Cache Section Helper Source: https://quarkus.io/guides/qute-reference Configure the CacheSectionHelper.Factory with a custom cache implementation, such as a map-based cache. This is automatically handled if the quarkus-cache extension is present. ```java // A simple map-based cache ConcurrentMap> map = new ConcurrentHashMap<>(); engineBuilder .addSectionHelper(new CacheSectionHelper.Factory(new Cache() { @Override public CompletionStage getValue(String key, Function> loader) { return map.computeIfAbsent(key, k -> loader.apply(k)); } })).build(); ``` -------------------------------- ### Conditional Logic with When Section Source: https://quarkus.io/guides/qute-reference Use the 'when' section for conditional logic similar to Java's switch. It matches a tested value against blocks sequentially until a condition is satisfied. The first matching block is executed. ```qute {#when items.size} {#is 1} __**(1)** There is exactly one item! {#is > 10} __**(2)** There are more than 10 items! {#else} __**(3)** There are 2 -10 items! {/when} ``` -------------------------------- ### Access Map Keys Source: https://quarkus.io/guides/qute-reference Iterate over map keys using `keySet` or `keys`. ```qute {#for key in map.keySet} ``` -------------------------------- ### Conditional Logic with if/else if/else Source: https://quarkus.io/guides/qute-reference Use this section to conditionally render content based on specified criteria. It supports multiple else if blocks and a final else block for default content. ```qute {#if item.name is 'sword'} It's a sword! __**(1)** {#else if item.name is 'shield'} It's a shield! __**(2)** {#else} Item is neither a sword nor a shield. __**(3)** {/if} ``` -------------------------------- ### Qute #let Section with Optional End Tag Source: https://quarkus.io/guides/qute-reference Demonstrates the usage of the #let section to define a local variable within a parent #if section. The #let section supports an optional end tag, with the compiler automatically adding it if omitted. ```html {#if item.isActive} {#let price = item.price} {price} // synthetic {/let} added here automatically {/if} // {price} cannot be used here! ``` -------------------------------- ### Render Template Asynchronously with CompletionStage Source: https://quarkus.io/guides/qute-reference Triggers asynchronous rendering and returns a CompletionStage. A callback can be registered to consume the result or process failures upon completion. ```java template.data(foo).renderAsync().whenComplete((result, failure) -> { if (failure == null) { // consume the output... } else { // process failure... } }; ``` -------------------------------- ### HTML Template with Item Details Source: https://quarkus.io/guides/qute An HTML template that renders the name and price of an item. Expressions like {item.name} and {item.price} are validated at build time. ```html {item.name}

    {item.name}

    Price: {item.price}
    ``` -------------------------------- ### Obtain and Render a Fragment Programmatically Source: https://quarkus.io/guides/qute-reference Shows how to obtain a specific template fragment by its identifier and render it with provided data using the `Template.getFragment()` method in Java. ```java @Inject Template item; String useTheFragment() { return item.getFragment("item_aliases") __**(1)** .data("aliases", List.of("Foo","Bar")) __**(2)** .render(); } ``` -------------------------------- ### Java Sample Data Class Source: https://quarkus.io/guides/qute A simple Java class representing a sample data item with properties for validity, name, and data. ```java public class Sample { public boolean valid; public String name; public String data; } ``` -------------------------------- ### Iterating with each loop Source: https://quarkus.io/guides/qute-reference Use the 'each' section to iterate over collections where 'it' is the implicit alias for the current iteration element. ```qute {#each items} {it.name} __**(1)** {/each} ``` -------------------------------- ### Referencing Templates from Other Resources Source: https://quarkus.io/guides/qute Demonstrates how a resource can reference a type-safe template declared in another resource class. ```java package org.acme.quarkus.sample; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import io.quarkus.qute.TemplateInstance; @Path("greeting") public class GreetingResource { @GET @Produces(MediaType.TEXT_PLAIN) public TemplateInstance get(@QueryParam("name") String name) { return HelloResource.Templates.hello(name); } } ``` -------------------------------- ### Formatting Temporal Objects with Pattern Source: https://quarkus.io/guides/qute-reference Format java.time objects using a specified pattern. ```qute {dateTime.format('d MMM uuuu')} ``` -------------------------------- ### Type-Safe Template with Java Record Source: https://quarkus.io/guides/qute-reference Declare a type-safe template using a Java record that implements TemplateInstance. The record components represent template parameters. The template file is expected at /src/main/resources/templates/HelloResource/Hello.html. ```java package org.acme.quarkus.sample; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import io.quarkus.qute.TemplateInstance; @Path("hello") public class HelloResource { record Hello(String name) implements TemplateInstance {} @GET @Produces(MediaType.TEXT_PLAIN) public TemplateInstance get(@QueryParam("name") String name) { return new Hello(name); } } ``` -------------------------------- ### Supplementary Localized File Source: https://quarkus.io/guides/qute-reference Define message templates in a supplementary localized file. Values defined in `io.quarkus.qute.i18n.Message#value()` are always prioritized over these. ```properties hello_name=Hello \ {name} and \ good morning! goodbye=Best regards, {name} __**(1)** ``` -------------------------------- ### Conditional Logic with Switch Section Source: https://quarkus.io/guides/qute-reference Use the 'switch' section as an alias for 'when' to match specific string values. It's useful for simple equality checks against known string inputs. ```qute {#switch person.name} {#case 'John'} __**(1)** Hey John! {#case 'Mary'} Hey Mary! {/switch} ``` -------------------------------- ### Add Default Section Helpers Source: https://quarkus.io/guides/qute-reference Register the default set of section helpers using `EngineBuilder.addDefaultSectionHelpers()`. ```java Engine engine = Engine.builder() .addDefaultSectionHelpers() .build(); ``` -------------------------------- ### Join Strings with Delimiter Source: https://quarkus.io/guides/qute-reference Join multiple string representations together with a specified delimiter using `str:join`. ```qute {str:join('_','Qute','is','cool')} ``` -------------------------------- ### Iterate Over Array Elements Source: https://quarkus.io/guides/qute-reference Use the `for` section to iterate over each element in an array. The current element is available as `element` within the loop. ```qute {#for element in myArray}
  • {element}
  • {/for} ``` -------------------------------- ### Conditional Variable Assignment with Let Section Source: https://quarkus.io/guides/qute-reference Use a '?' suffix on a variable name in a 'let' section to conditionally set the variable only if the key without '?' resolves to null or is not found. This acts as a default value. ```qute {#let enabled?=true} __**(1)** __**(2)** {#if enabled}ON{/if} {/let} ``` -------------------------------- ### Localized Enum Constant Message Keys Source: https://quarkus.io/guides/qute-reference Localized files must contain keys for each enum constant, typically formed by the method name, an underscore, and the constant name. Use '_$' separator if constant names contain '_' or '$'. ```properties methodName_CONSTANT1=Value 1 methodName_CONSTANT2=Value 2 ``` -------------------------------- ### Register Custom Template Instance Initializer Source: https://quarkus.io/guides/qute-reference Add a custom `TemplateInstance.Initializer` to the engine builder to customize template instance initialization. ```java Engine engine = Engine.builder() .addTemplateInstanceInitializer(new MyTemplateInstanceInitializer()) .build(); ``` -------------------------------- ### Multiple Conditions in If Section Source: https://quarkus.io/guides/qute-reference Combines multiple conditions using logical AND to create more specific rendering logic. ```qute {#if item.age > 10 && item.price > 500} This item is very old and expensive. {/if} ``` -------------------------------- ### Formatting Temporal Objects with Pattern and Locale Source: https://quarkus.io/guides/qute-reference Format java.time objects using a specified pattern and locale. ```qute {dateTime.format('d MMM uuuu',myLocale)} ``` -------------------------------- ### Accessing Iteration Metadata with each Source: https://quarkus.io/guides/qute-reference Inside an {#each} loop, access iteration metadata like count, index, and status flags using the 'it_' prefix. ```qute {#each items} {it_count}. {it.name} __**(1)** {#if it_hasNext}
    {/if} __**(2)** {/each} ``` -------------------------------- ### Formatting Various Date/Time Types with Pattern and Locale Source: https://quarkus.io/guides/qute-reference Format temporal objects (java.time, java.util.Date, java.util.Calendar, Number) using a specified pattern and locale. ```qute {time:format(myDate,'d MMM uuuu', myLocale)} ``` -------------------------------- ### Maven Dependencies for Qute and Scheduler Source: https://quarkus.io/guides/qute Add these dependencies to your pom.xml to enable the Quarkus Qute templating engine and the Quarkus Scheduler for periodic tasks. ```xml io.quarkus quarkus-qute io.quarkus quarkus-scheduler ``` -------------------------------- ### Basic If Section Source: https://quarkus.io/guides/qute-reference Renders content if the condition evaluates to true. A condition without an operator is true if the value is not considered falsy. ```qute {#if item.active} This item is active. {/if} ``` -------------------------------- ### Formatting Various Date/Time Types with Pattern Source: https://quarkus.io/guides/qute-reference Format temporal objects (java.time, java.util.Date, java.util.Calendar, Number) using a specified pattern. ```qute {time:format(myDate,'d MMM uuuu')} ``` -------------------------------- ### Java Template Extension for Discounted Price Source: https://quarkus.io/guides/qute This Java class defines a static template extension method 'discountedPrice' for the 'Item' class. It calculates a 10% discounted price and can be invoked from Qute templates as if it were a property of the Item object. ```java package org.acme.quarkus.sample; import io.quarkus.qute.TemplateExtension; import java.math.BigDecimal; @TemplateExtension public class TemplateExtensions { public static BigDecimal discountedPrice(Item item) { return item.price.multiply(new BigDecimal("0.9")); } } ``` -------------------------------- ### Dynamic Template Inclusion with '_id' Parameter Source: https://quarkus.io/guides/qute-reference Dynamically specify the template to include by using the '_id' parameter. The value of '_id' is resolved as an expression to determine the template ID. ```qute {#include _id=bar.foo /} ``` -------------------------------- ### User Tag Template with Arguments Metadata Source: https://quarkus.io/guides/qute-reference A Qute tag template 'tags/test.html' that displays the first unnamed parameter ('it'), a named parameter ('readonly'), and HTML attributes generated from other arguments using '_args.filter().asHtmlAttributes()'. ```html {it} {readonly} {_args.filter('readonly').asHtmlAttributes} ``` -------------------------------- ### Default Message Bundle Naming Source: https://quarkus.io/guides/qute-reference Demonstrates the default naming convention for message bundles based on class hierarchy. The bundle name is derived from enclosing class names and the interface name, separated by underscores. ```java class Controller { @MessageBundle interface index { @Message("Hello {name}!") String hello(String name); } } ``` -------------------------------- ### Formatting Various Date/Time Types with Pattern, Locale, and TimeZone Source: https://quarkus.io/guides/qute-reference Format temporal objects (java.time, java.util.Date, java.util.Calendar, Number) using a specified pattern, locale, and time zone. ```qute {time:format(myDate,'d MMM uuuu',myLocale,myTimeZoneId)} ``` -------------------------------- ### Manually Cache a Template Source: https://quarkus.io/guides/qute-reference Parse a template manually and add it to the Qute engine's cache using `Engine.putTemplate()`. ```java Template template = engine.getTemplate("myTemplate.html"); engine.putTemplate("myTemplate.html", template); ``` -------------------------------- ### Iterating with for loop and custom alias Source: https://quarkus.io/guides/qute-reference Use the 'for' section to iterate over collections and specify a custom alias for the iteration element. ```qute {#for item in items} __**(1)** {item.name} {/for} ``` -------------------------------- ### Simplify Template Structure with 'with' Section Source: https://quarkus.io/guides/qute-reference Use the 'with' section to set the current context object, simplifying nested property access. This is useful for reducing redundancy in templates. ```qute {#with item.parent}

    {name}

    __**(1)**

    {description}

    __**(2)** {/with} ```