spullara 小胡子 java 部分

spullara mustache java partials

我无法找到有关如何使用 Spullara Mustache java 实现实现分音的示例。他们的 github 页面似乎没有任何直接的部分示例。

在 DefaultMustacheFactory 中,我看到了 compilePartial 和 resolvePartialPath 的方法,但我不确定我是否应该覆盖它们或什么。

我目前有这个,没有部分效果也很好。 TemplateContent 包含原始模板 html,包括 mustache 语法。

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

非常简单。但是,如果模板内容中有 {{>partialName}} 怎么办?我想我也需要以某种方式指定该模板内容。

我是否需要扩展 DefaultMustacheFactory 或者可能需要扩展另一个 class 来指定我的部分名称及其内容?

我想我只是错过了一些东西。

谢谢, 马特

假设您的模板文件存储在文件夹 'src/main/resources/org/example/web/' 中,并且您有一个模板 "page.html" 文件引用另外两个模板文件 'header.html' 和 'footer.html'。您的模板文件 "page.html" 应如下所示:

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

... some content ...

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