Open angelozerr opened 11 months ago
Actually, I think the theory is that I should define a Java class to declare the tags parameters, I'm sure I discussed it with @mkouba but I can't find where. Something like:
public class tags {
@CheckedTemplates
public static class Templates {
public static native TemplateInstance myUser(User user);
}
}
Or was it?
@CheckedTemplates
public class tags {
public static native TemplateInstance myUser(User user);
}
I can't recall.
It's been discussed in https://github.com/quarkusio/quarkus/issues/21859 though, as well as default parameter values (added in https://github.com/quarkusio/quarkus/pull/25488). I don't know if we can declare default template parameter values from the Java side, though. Perhaps only when declaring parameters in the template?
Otherwise, we can declare tags/myUser.html
as such:
{@model.User user}
Login: {user.login}
Otherwise, we can declare tags/myUser.html as such:
Indeed it is working. I think it is the best solution, no?
You can both a type-safe template that corresponds to templates/tags/myUser.html
or a parameter declaration inside the tag template (e.g. {@org.acme.User user}
).
Both
@CheckedTemplates
public class tags {
static native TemplateInstance myUser(User user);
}
and
@CheckedTemplate(basePath = "tags"
public class Whatever {
static native TemplateInstance myUser(User user);
}
should work.
Both solutions are equally good.
So I wasn't wrong, yay :)
I didn't find this documented in https://quarkus.io/guides/qute-reference#typesafe_templates though, probably it should, no?
So I wasn't wrong, yay :)
I didn't find this documented in https://quarkus.io/guides/qute-reference#typesafe_templates though, probably it should, no?
Well, tags are regular templates located in a special folder (templates/tags
) and a special section is registered each. Otherwise the same rules apply. Of course, we could add a NOTE or something... feel free to send a PR ;-).
Given this user tag
src/main/resources/tags/myUser.html
:At this step, we cannot know what is user
Given a Qute template which consumes the user tag
At this step we can inject the
org.acme.User
Java type inside themyUser.html
which will provide completion, validation, hover, defintion,etcThis feature is very important to support for instance https://github.com/FroMage/RivieraDEV-Quarkus/blob/main/src/main/resources/templates/tags/organisers.html