You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _versions/main/guides/qute-reference.adoc
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2095,6 +2095,44 @@ class ItemService {
2095
2095
2096
2096
NOTE: You can specify `@CheckedTemplate#ignoreFragments=true` in order to disable this feature, i.e. a dollar sign `$` in the method name will not result in a checked fragment method.
2097
2097
2098
+
[[template_contents]]
2099
+
==== Template Contents
2100
+
2101
+
It is also possible to specify the contents for a type-safe template directly in your Java code.
2102
+
A `static native` method of a class annotated with `@CheckedTemplate` or a Java record that implements `TemplateInstance` may be annotated with `@io.quarkus.qute.TemplateContents`.
2103
+
The annotation value is used as the template contents.
2104
+
The template id/path is derived from the type-safe template.
2105
+
2106
+
.Template Contents Example
2107
+
[source,java]
2108
+
----
2109
+
package org.acme.quarkus.sample;
2110
+
2111
+
import jakarta.inject.Inject;
2112
+
import jakarta.ws.rs.GET;
2113
+
import jakarta.ws.rs.Path;
2114
+
import jakarta.ws.rs.QueryParam;
2115
+
import jakarta.ws.rs.Produces;
2116
+
import jakarta.ws.rs.core.MediaType;
2117
+
2118
+
import io.quarkus.qute.TemplateContents;
2119
+
import io.quarkus.qute.TemplateInstance;
2120
+
2121
+
@Path("hello")
2122
+
public class HelloResource {
2123
+
2124
+
@TemplateContents("Hello {name}!") <1>
2125
+
record Hello(String name) implements TemplateInstance {}
2126
+
2127
+
@GET
2128
+
@Produces(MediaType.TEXT_PLAIN)
2129
+
public TemplateInstance get(@QueryParam("name") String name) {
2130
+
return new Hello(name);
2131
+
}
2132
+
}
2133
+
----
2134
+
<1> Defines the contents for the type-safe template represented by the `Hello` record. The derived template id is `HelloResource/Hello`.
0 commit comments