Qute is a server-side templating engine provided as a Quarkus extension. It combines templates with supplied parameters to produce HTML pages or other documents. In a web application, it can render both complete pages and smaller HTML fragments returned by REST endpoints. section 6.1.1 section 6.5
To serve a Qute-generated page in Quarkus:
- Add quarkus-qute for templating and quarkus-rest-qute to expose rendered templates through REST endpoints. section 6.1
- Place a template under src/main/resources/templates and give it placeholders for values supplied by the application. section 6.1.1
- Return a TemplateInstance from a REST method that produces HTML. The REST-Qute extension processes the instance into the response document. section 6.1.1
Show the current user
A whoami.html template can greet {name ?: 'anonymous'}. A /whoami REST resource injects the matching Template and a SecurityContext, then returns whoami.data("name", userId). Until authentication is configured, there is no logged-in username, so the page displays “Hello anonymous!”; Qute renders the value but does not itself establish the user’s identity. section 6.1.1
For an interactive reservation page, use separate Qute templates for the main page, the reservations table, and the available-cars table. REST methods supply each template’s data and return HTML. HTMX, a separate client-side library, requests those fragments and swaps them into the page; Qute remains responsible for server-side rendering. Templates can declare parameter types, and @CheckedTemplate provides optional build-time type-safety checks for Java objects passed to them. section 6.2.3 section 6.6
Listing 6.16 Building template instances with type safety
@CheckedTemplate
public static class Templates {
public static native TemplateInstance index(
LocalDate startDate,
LocalDate endDate,
String name);
public static native TemplateInstance listofreservations(
Collection<Reservation> reservations);
public static native TemplateInstance availablecars(
Collection<Car> cars,
LocalDate startDate,
LocalDate endDate);
}
The @CheckedTemplate declarations show how the index, reservations, and available-cars templates receive typed values when their TemplateInstance objects are created. section 6.2.3
