如何使用StringTemplate进行标准布局?

Ale*_*sky 2 stringtemplate

使用StringTemplate,有一个标准布局模板的正确方法是什么,例如:

<head>
..
</head>

<html>

$body()$

</html>
Run Code Online (Sandbox Code Playgroud)

我可以从我的应用程序设置主体模板,以便我使用的每个模板都使用这个基本布局?

谢谢.

Ale*_*sky 5

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

"包含其名称通过expr计算的模板.参数列表是属性赋值的列表,其中每个赋值的格式为attribute = expr.示例$(whichFormat)()$查找whichFormat的值并将其用作模板名称.也可以将间接模板应用于属性."

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

<head>
    <title>Sportello</title>
</head>

<html lang="en-US">
<body>
    $partials/header()$
    <section>$(body_template)()$</section>
    $partials/footer()$
</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

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