Reputation:
Let's say I have a Page.ss and PageType.ss templates in Layout folder.
Page.ss:
<div><!--content of PageType.ss here --></div>
PageType.ss has some content to be passed to Page.ss and viewed alltogether. Page's content will remain the same for different PageTypes so I'd like not to have duplicate markup. I've found renderWith() but I can't make it to work. I can use conditional includes but it just doesn't feel right. Is this possible or am I all wrong?
Upvotes: 0
Views: 157
Reputation: 4626
The usual template structur in SilverStripe (3) is:
/templates/ Main folder for all templates
/templates/Page.ss Main template for all pages. Has $Layout include the pagetype-specific content
/templates/Layout/ holds templates for $Layout
/templates/Layout/Page.ss replaces $Layout for page type "Page"
/template/Layout/OtherPageType.ss $Layout for "OtherPageType"
/templates/Includes/ stuff that is included using <% include %>
/templates/Includes/Header.ss
/templates/Includes/Footer.ss
So your main template might look like
<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>
See also SilverStripe lessons
Upvotes: 1
Reputation: 1809
You can pass parameters to includes within the templates.
Page.ss
<div>
<% include PageType Variable1=$Variable1, Variable2=$Variable2
</div>
PageType.ss will need to be in the templates/Includes directory.
Checkout the reference https://docs.silverstripe.org/en/3/developer_guides/templates/syntax/#includes
Upvotes: 1