prabello prabello - 11 months ago 69
Java Question

How to get mustache html in java

I'm trying to use mustache to fill an html for me, then i want to get that html and use it as String.

A template like this -> template.xhtml

<table style="width:10%" align="center">

With a Hash like this:

HashMap<String, String> scopes = new HashMap<String, String>();
scopes.put("old", "Testing");
scopes.put("new", "Mustache");

Now how do i tell, Mustache to use template.xhtml and fill with scopes and then return me the html?

Answer Source
String aux = "";    
MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile("path/to/file.html");
    StringWriter stringWriter = new StringWriter();
    mustache.execute(stringWriter, wrapper);
    aux = stringWriter.toString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download