Skip to content

zandero/templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

templates

Wrapper and helpers around Mustache templates

Setup

<dependency>      
     <groupId>com.zandero</groupId>      
     <artifactId>templates</artifactId>      
     <version>1.4</version>      
</dependency>

Mustache utils usage

Basic use

    MustacheUtils utils = new MustacheUtils();
    Mustache template = utils.load("/templates/hello.html");
    
    Map<String, String> data = new HashMap<>();
    data.put("name", "world");
    
    String result = utils.render(template, data);

Use JSON instead of Map for data

    MustacheUtils utils = new MustacheUtils();
    Mustache template = utils.load("/templates/hello.html");
    String result = utils.renderJson(template, "{\"name\": \"world\"}");

Use name value pairs

    MustacheUtils utils = new MustacheUtils();
    Mustache template = utils.load("/templates/hello.html");
    String result = utils.renderStrings(template, "name", "world");

Templates usage

Class wrapping MustacheUtils to simplify usage.

    Map<String, Object> data = new HashMap<>();
    data.put("name", "world");
    String result = Templates.render("/templates/hello.html", data);
    String result = Templates.renderJson("/templates/hello.html", "{\"name\": \"world\"}");

Tamplate inside template

Using a base template to wrap around other templates.

Releases

No releases published

Packages

No packages published