Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spullara mustache java partials

I'm having trouble finding examples of how to implement partials using the Spullara Mustache java implementation. Their github page doesn't seem to have any straight forward partial examples.

In DefaultMustacheFactory I see methods for compilePartial and resolvePartialPath, but I'm not sure if I am supposed to override them or what.

I currently have this, and it works great without partials. TemplateContent contains the raw template html including mustache syntax.

    public Mustache compileMustacheTemplate(String templateCode, String templateContent){
        return new DefaultMustacheFactory().compile(new StringReader(templateContent),templateCode);
    }

Pretty straight forward. But what if template content had {{>partialName}} inside it? I think I need to somehow specify that template content as well.

Do I need to extend DefaultMustacheFactory or possibly another class to specify the name of my partial and the content for it?

I believe I'm just missing something.

Thanks, Matt

like image 385
Matt Ashley Avatar asked Oct 31 '22 08:10

Matt Ashley


1 Answers

Assuming your template files are stored in a folder 'src/main/resources/org/example/web/' and you have one template "page.html" file referencing two other template files 'header.html' and 'footer.html'. Your template file "page.html" should look like this:

{{> src/main/resources/org/example/web/header.html}}

... some content ...

{{> src/main/resources/org/example/web/footer.html}}
like image 126
Nikola Avatar answered Nov 09 '22 16:11

Nikola