使用 StringTemplate 4 将一个模板嵌套在另一个模板中
我在理解如何将另一个模板嵌套在另一个模板中时遇到问题。例如,我有 3 个模板:application.stg、wrapper.stg 和 core.stg。
core.stg:
page(data1, data2) ::= <<
<h1>$data1$</h1>
<h1>$data2$</h1>
>>
wrapper.stg:
page(data3, data4) ::= <<
<h1>$data3$</h1>
<!----- CORE.STG GOES HERE ------->
<h1>$data4$</h1>
>>
application.stg:
page(data7, data8) ::= <<
<h1>$data7$</h1>
<!----- WRAPPER.STG GOES HERE ------->
<h1>$data8$</h1>
>>
文档似乎暗示这是可能的(条件子模板部分),但抱歉,我根本无法弄清楚语法。请帮帮我。
I am having problem understanding how to nest another template inside another. For example, I have 3 templates: application.stg, wrapper.stg and core.stg.
core.stg:
page(data1, data2) ::= <<
<h1>$data1lt;/h1>
<h1>$data2lt;/h1>
>>
wrapper.stg:
page(data3, data4) ::= <<
<h1>$data3lt;/h1>
<!----- CORE.STG GOES HERE ------->
<h1>$data4lt;/h1>
>>
application.stg:
page(data7, data8) ::= <<
<h1>$data7lt;/h1>
<!----- WRAPPER.STG GOES HERE ------->
<h1>$data8lt;/h1>
>>
The documentation seems to hint that this is possible (Conditional Subtemplate section), but sorry, I could not figure out the syntax at all. Please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用每个模板创建一个完整文件,并确保为其设置
.stg
扩展名。然后创建一个
TemplateGroupFile
对象并设置属性data7
和data8
并告诉它在应用程序模板中启动。这是 C# 代码
You can create a whole file with every template and make sure you set the
.stg
extension to it.Then create a
TemplateGroupFile
object and set the propertiesdata7
anddata8
and tell it to start in the application template.This is the C# code