开发者

How to do standard layouts with StringTemplate?

开发者 https://www.devze.com 2023-01-30 09:57 出处:网络
With StringTemplate, what is the proper way to have a standard layout template s开发者_JS百科uch as:

With StringTemplate, what is the proper way to have a standard layout template s开发者_JS百科uch as:

<head>
..
</head>

<html>

$body()$

</html>

Where I can set the body template from my application, so that every template I use uses this fundamental layout?

Thanks.


I found it hiding in the documentation: http://www.antlr.org/wiki/display/ST/StringTemplate+2.2+Documentation

"Include template whose name is computed via expr. The argument-list is a list of attribute assignments where each assignment is of the form attribute=expr. Example $(whichFormat)()$ looks up whichFormat's value and uses that as template name. Can also apply an indirect template to an attribute."

So my main layout template now looks like this:

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

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

...to which I pass the subtemplate's name as an attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号