Emerjoin / Hi-Framework-features

Java EE Framework
5 stars 1 forks source link

Template transformers #119

Closed Emerjoin closed 7 years ago

Emerjoin commented 7 years ago

Template transformers are CDI Managed beans that have the capability of transforming templates: add stylesheet references, add script references, replace content or any other operation. The transformers are executed on the first time a template is loaded, during deployment.

Why add Template transformers?

Because a template is declared in one place, one single time, one single artifact, but there situation we need the template to load content dynamically based in the context the template is being used.

How to make a template transformable

   <templates>
            <template transformable="true">index</template>
            <template>second</template>
     </templates>

Template transformer example


@ApplicationScoped
public class Transformer {

      @Overrides
      public void transform(@Observes TemplateTransformEvent event){
             Template template = event.getTemplate();
             template.appendScript("script/path");
             template.appendStylesheet("script/path");
             template.appendElement("script/path");
      }

}