Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import issues in qute documentation examples #34658

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/src/main/asciidoc/qute-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,9 @@ import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import io.quarkus.qute.TemplateInstance;

@Path("hello")
Expand Down Expand Up @@ -2472,6 +2475,8 @@ import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.Template;
Expand Down
22 changes: 14 additions & 8 deletions docs/src/main/asciidoc/qute.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ https://github.com/quarkusio/quarkus/tree/main/docs/src/main/asciidoc
= Qute Templating Engine
include::_attributes.adoc[]
:categories: miscellaneous
:summary: Learn more about how you can use templating in your applications with the Qute template engine.
:summary: Learn more about how you can use templating in your applications with the Qute template engine.

Qute is a templating engine designed specifically to meet the Quarkus needs.
The usage of reflection is minimized to reduce the size of native images.
Expand Down Expand Up @@ -84,6 +84,8 @@ import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.Template;
Expand All @@ -102,7 +104,7 @@ public class HelloResource {
}
----
<1> If there is no `@Location` qualifier provided, the field name is used to locate the template. In this particular case, we're injecting a template with path `templates/hello.txt`.
<2> `Template.data()` returns a new template instance that can be customized before the actual rendering is triggered. In this case, we put the name value under the key `name`. The data map is accessible during rendering.
<2> `Template.data()` returns a new template instance that can be customized before the actual rendering is triggered. In this case, we put the name value under the key `name`. The data map is accessible during rendering.
<3> Note that we don't trigger the rendering - this is done automatically by a special `ContainerResponseFilter` implementation.

If your application is running, you can request the endpoint:
Expand Down Expand Up @@ -146,6 +148,8 @@ import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.CheckedTemplate;
Expand All @@ -167,7 +171,7 @@ public class HelloResource {
----
<1> This declares a template with path `templates/HelloResource/hello`.
<2> `Templates.hello()` returns a new template instance that is returned from the resource method. Note that we don't trigger the rendering - this is done automatically by a special `ContainerResponseFilter` implementation.

NOTE: Once you have declared a `@CheckedTemplate` class, we will check that all its methods point to existing templates, so if you try to use a template from your Java code and you forgot to add it, we will let you know at build time :)

Keep in mind this style of declaration allows you to reference templates declared in other resources too:
Expand All @@ -181,6 +185,8 @@ import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import io.quarkus.qute.TemplateInstance;

Expand Down Expand Up @@ -217,7 +223,7 @@ public class Templates {
<1> This declares a template with path `templates/hello`.


== Template Parameter Declarations
== Template Parameter Declarations

If you declare a *parameter declaration* in a template then Qute attempts to validate all expressions that reference this parameter and if an incorrect expression is found the build fails.

Expand Down Expand Up @@ -247,7 +253,7 @@ Let's start again with the template:
</head>
<body>
<h1>{item.name}</h1>
<div>Price: {item.price}</div> <2>
<div>Price: {item.price}</div> <2>
</body>
</html>
----
Expand Down Expand Up @@ -310,7 +316,7 @@ Let's start again with the template:
</head>
<body>
<h1>{item.name}</h1>
<div>Price: {item.price}</div>
<div>Price: {item.price}</div>
</body>
</html>
----
Expand Down Expand Up @@ -341,7 +347,7 @@ public class ItemResource {

@Inject
Template item; <1>

@GET
@Path("{id}")
@Produces(MediaType.TEXT_HTML)
Expand Down Expand Up @@ -377,7 +383,7 @@ Let's update our template:
</head>
<body>
<h1>{item.name}</h1>
<div>Price: {item.price}</div>
<div>Price: {item.price}</div>
{#if item.price > 100} <1>
<div>Discounted Price: {item.discountedPrice}</div> <2>
{/if}
Expand Down