假设我在布局文件夹中有 Page.ss 和 PageType.ss 模板。
Page.ss :
<div><!--content of PageType.ss here --></div>
PageType.ss有一些内容要传递给Page.ss并一起查看。对于不同的PageTypes,Page的内容将保持不变,因此我不希望重复标记。我找到了renderWith(),但我无法使它工作。我可以使用条件包括,但它感觉不对。这可能还是我错了?
答案 0 :(得分:1)
您可以将参数传递给模板中的包含。
<强> Page.ss 强>
<div>
<% include PageType Variable1=$Variable1, Variable2=$Variable2
</div>
PageType.ss需要位于templates / Includes目录中。
查看参考https://docs.silverstripe.org/en/3/developer_guides/templates/syntax/#includes
答案 1 :(得分:1)
SilverStripe(3)中常用的模板结构是:
/ templates / 所有模板的主文件夹
/templates/Page.ss 所有网页的主要模板。 $ Layout包含特定于页面类型的内容
/ templates / Layout / 包含$ Layout
的模板/templates/Layout/Page.ss 替换页面类型为“页面”的$ Layout
/template/Layout/OtherPageType.ss $“OtherPageType”的布局
使用&lt;%include%&gt; 包含的/ templates / Includes / 内容
/templates/Includes/Header.ss
/templates/Includes/Footer.ss
所以你的主模板可能看起来像
<html>
<head>
...
</head>
<body>
<% include Header %>
//other markup for sidebar etc...
$Layout //this is where paget type specific stuff comes in, located in /templates/Layout
<% include Footer %>
</body>
</html>