liveBook · Manning

Template

As explained in Quarkus in Action

A Qute template is a structured document containing markup and Qute expressions that can be rendered with supplied parameters.

A Qute template combines HTML with expressions that are filled when a REST method renders it. For an interactive reservation page, keep the main page and its replaceable tables in separate templates: index.html, listofreservations.html, and availablecars.html. HTMX requests the table fragments and inserts their HTML into the page without custom JavaScript. section 6.2.3

To serve a template:

  • Declare its inputs, such as a user name, dates, or a collection of cars. section 6.2.3
  • Use expressions such as {name} for values and {#for car in cars} to produce table rows. section 6.2.3
  • Return a TemplateInstance from a REST method; @CheckedTemplate methods provide typed arguments for each template. section 6.2.3
Listing 6.12 Template for the table of available cars
{@org.acme.users.model.Car[] cars}  #1
{@java.time.LocalDate startDate}
{@java.time.LocalDate endDate}
<div id="carlist">
<table>
  <thead>
  <tr>
    <th>Car ID</th>
    <th>Plate number</th>
    <th>Manufacturer</th>
    <th>Model</th>
    <th>Reservation</th>
  </tr>
  </thead>
  {#for car in cars}  #2
    <tr>
    <td>{car.id}</td>
    <td>{car.licensePlateNumber}</td>
    <td>{car.manufacturer}</td>
    <td>{car.model}</td>
    <td>
      <form hx-target="#reservations"  #3
            hx-post="/reserve">
        <input type="hidden" name="startDate" value="{startDate}"/>
        <input type="hidden" name="endDate" value="{endDate}"/>
        <input type="hidden" name="carId" value="{car.id}"/>
        <input type="submit" value="Reserve"/>
      </form>
     </td>
    </tr>
  {/for}
</table>
</div>

The available-cars fragment shows typed inputs, a loop over cars, and an HTMX reservation form in one template. section 6.2.3

How Quarkus in Action covers it

How deep it goes
Works through template inputs, expressions, loops, and REST rendering without detailing Qute engine internals.
Examples
Uses a reservation header, available-cars table, and reservations table.
What it assumes
Assumes familiarity with HTML and REST while illustrating Qute expressions and HTMX attributes through examples.
What you can do after
Build it from scratch: render separate page and table templates through REST methods for an HTMX-driven UI.
How it connects
Connects Qute with HTMX, REST methods, and checked templates.

Also explained in

Compare how 21 books explain template →

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.