liveBook · Manning

Qute

As explained in Quarkus in Action

quarkus-qute is a Quarkus extension that integrates the Qute templating engine into Quarkus applications.

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

How Quarkus in Action covers it

How deep it goes
Works through template files, parameter binding, REST responses, fragments, and optional type checks; does not detail Qute engine internals.
Examples
Uses an anonymous-fallback greeting and a reservation page with separate reservations and available-cars tables.
What it assumes
Assumes familiarity with Java REST resources and HTML, while demonstrating Qute template creation from a simple page.
What you can do after
Build it from scratch as Quarkus REST endpoints that return Qute-rendered pages and fragments for HTMX updates.
How it connects
Connects REST endpoints, SecurityContext, checked templates, and HTMX-driven HTML updates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.