Package gg.jte

Interface Content

All Known Subinterfaces:
HtmlContent
All Known Implementing Classes:
CssClasses

public interface Content
This interface can be used to create reusable content blocks for templates through Java code. When using the content block shorthand @`...` in templates, behind the scenes an anonymous class of Content is created as well. For example:
     !{var name = "world";}
     !{var myContent = @`
         Hello ${name}!
         This is a reusable content block.
     `;}

     ${myContent}
     ${myContent}
 
Would be the same as:
     public class MyContent implements Content {
         private final String name;

         public MyContent(String name) {
             this.name = name;
         }

         @Override
         public void writeTo(TemplateOutput output) {
             output.writeContent("Hello ");

             // User provided content, must be output escaped!
             output.writeUserContent(name);

             output.writeContent("!\n This is a reusable content block.");
         }
     }
 
While the above example doesn't make a lot of sense, Content can be a very powerful abstraction for complex tasks.