Skip to content

Commit

Permalink
Update docs/src/main/asciidoc/qute.adoc
Browse files Browse the repository at this point in the history
Co-authored-by: Neon <[email protected]>
Qute docs improvement
Update docs/src/main/asciidoc/qute.adoc

Co-authored-by: Neon <[email protected]>
Qute docs improvement
  • Loading branch information
melloware committed Nov 4, 2024
1 parent 0fbfc31 commit de6d636
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions docs/src/main/asciidoc/qute.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ Hello Martin!
There's an alternate way to declare your templates in your Java code, which relies on the following convention:

- Organise your template files in the `/src/main/resources/templates` directory, by grouping them into one directory per resource class. So, if
your `ItemResource` class references two templates `hello` and `goodbye`, place them at `/src/main/resources/templates/ItemResource/hello.txt`
and `/src/main/resources/templates/ItemResource/goodbye.txt`. Grouping templates per resource class makes it easier to navigate to them.
your `HelloResource` class references two templates `hello` and `goodbye`, place them at `/src/main/resources/templates/HelloResource/hello.txt`
and `/src/main/resources/templates/HelloResource/goodbye.txt`. Grouping templates per resource class makes it easier to navigate to them.
- In each of your resource class, declare a `@CheckedTemplate static class Template {}` class within your resource class.
- Declare one `public static native TemplateInstance method();` per template file for your resource.
- Use those static methods to build your template instances.
Expand All @@ -162,6 +162,13 @@ Hello {name}! <1>
----
<1> `{name}` is a value expression that is evaluated when the template is rendered.

.HelloResource/goodbye.txt
[source]
----
Goodbye {name}! <1>
----
<1> `{name}` is a value expression that is evaluated when the template is rendered.

Now let's declare and use those templates in the resource class.

.HelloResource.java
Expand Down Expand Up @@ -201,7 +208,7 @@ NOTE: Once you have declared a `@CheckedTemplate` class, we will check that all

Keep in mind this style of declaration allows you to reference templates declared in other resources too:

.HelloResource.java
.Goodbye.java
[source,java]
----
package org.acme.quarkus.sample;
Expand All @@ -221,7 +228,7 @@ public class GoodbyeResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public TemplateInstance get(@QueryParam("name") String name) {
return HelloResource.Templates.hello(name);
return HelloResource.Templates.goodbye(name);
}
}
----
Expand All @@ -243,9 +250,11 @@ import io.quarkus.qute.CheckedTemplate;
@CheckedTemplate
public class Templates {
public static native TemplateInstance hello(String name); <1>
public static native TemplateInstance goodbye(String name); <2>
}
----
<1> This declares a template with path `templates/hello`.
<2> This declares a template with path `templates/goodbye`.


== Template Parameter Declarations
Expand Down

0 comments on commit de6d636

Please sign in to comment.