【问题标题】:How to do standard layouts with StringTemplate?如何使用 StringTemplate 进行标准布局?
【发布时间】:2010-12-15 03:17:29
【问题描述】:

使用 StringTemplate,拥有标准布局模板的正确方法是:

<head>
..
</head>

<html>

$body()$

</html>

我可以在哪里设置我的应用程序的正文模板,以便我使用的每个模板都使用这个基本布局?

谢谢。

【问题讨论】:

    标签: stringtemplate


    【解决方案1】:

    我发现它隐藏在文档中: http://www.antlr.org/wiki/display/ST/StringTemplate+2.2+Documentation

    "包含名称为的模板 通过 expr 计算。参数列表 是属性分配的列表 其中每个作业的形式为 属性=表达式。例子 $(whichFormat)()$ 查找 whichFormat 的值并将其用作 模板名称。也可以申请一个 属性的间接模板。”

    所以我的主要布局模板现在看起来像这样:

    <head>
        <title>Sportello</title>
    </head>
    
    <html lang="en-US">
    <body>
        $partials/header()$
        <section>$(body_template)()$</section>
        $partials/footer()$
    </body>
    </html> 
    

    ...我将子模板的名称作为属性传递给它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-03
      • 2021-05-19
      • 2021-04-02
      • 2011-06-03
      • 2018-01-13
      • 2017-05-23
      • 1970-01-01
      相关资源
      最近更新 更多