0

If I set an attribute in a template instance, i.e.

index.setAttribute("locale", Locale.CANADA_FRENCH);

Then how can I read the attribute locale in the template?
{attributes['locale']}, {attribute['locale']}, {attributes.get('locale'} don't work.

1 Answers1

0

This does not work out of the box. Somethig like this should do the trick:

    templateInstance.data("attrs", new io.quarkus.qute.Mapper() {
       Object get(String key) {
          return templateInstance.getAttribute(key);
       }
       boolean appliesTo(String key) {
          return templateInstance.getAttribute(key) != null;
       }
    });

And in the template:

    {data:attrs.locale}

If you believe that it would be a useful addition pls feel free to create a new enhancement issue.

Martin Kouba
  • 1,121
  • 5
  • 8
  • So. please, what's the use for attributes? The guide tells about only the keys "selectedVariant" and "locale". – Dario Scoppelletti Jun 14 '23 at 12:52
  • Oh, yes, there is the TemplateAttribute annotation to pass the value of an attribute to a template exception. Nothing else? There is already https://github.com/quarkusio/quarkus/issues/25785, but it is closed. – Dario Scoppelletti Jun 14 '23 at 13:13
  • Yes, the selected variant and locale are the attribute we use in RESTEasy Reactive integration and message bundles. Template extension methods can also consume attributes. And you can also access attributes in custom sections via `io.quarkus.qute.ResolutionContext.getAttribute()`. – Martin Kouba Jun 15 '23 at 08:37
  • The issue was closed because there was no demand for this feature. Feel free to create a new one and describe your use case pls. – Martin Kouba Jun 15 '23 at 08:38