Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Repeating HTML structure for different includes


Reply


3 Posts   619 Views

Avatar
sb

Community Member, 2 Posts

25 May 2012 at 2:05am

Edited: 25/05/2012 2:29am

hello,

i'm a frontend designer with small programming knowledge and have the following question:

<aside>
..
..
<% if getFeaturedCount %>
<div class="block">
<div class="header">
<h2>Project Featured</h2>
</div>
<div class="content">
<div class="list">
<% control getProjectFeatured %>
<div class="item">
<ul>
<li><a href="$Link">$title</a></li>
<li>$shorttitle</li>
<li>$year</li>
</ul>
</div>
<% end_control %>
</div>
</div>
</div>
<% end_if %>
<% if getLabCount %>
<div class="block">
<div class="header">
<h2>Labs</h2>
</div>
<div class="content">
<div class="list">
<% control getLabList %>
<div class="item">
<ul>
<li><a href="$Link">$name</a></li>
<li>$subtitle</li>
<li>$Logo</li>
</ul>
</div>
<% end_control %>
</div>
</div>
</div>
<% end_if %>
..
..
</aside>

i have structures like above (typical sidebar blocks) and as you can see i have to print the output of different models (datatypes) in the always same html structure

<div class="block">
<div class="header">

TITLE

</div>
<div class="content">

ITEMS

</div>
</div>

in smarty for example i would include another template for each block and give parameters with it (TITLE, ITEMS) and
would end with the following:

<aside>
...
...
{include myblock.html
title="Project Featured",
items=$getProjectFeatured()}

{include myblock.html
title="Labs",
items=$getLabList()}

...
...
</aside>

how to do this in silverstripe?

thanks and best regards sb

Avatar
sb

Community Member, 2 Posts

31 May 2012 at 12:24am

maybe someone can tell me if there is something similar like the smarty example in silverstripe core or if somebody has to programme something special for this ...

Avatar
swaiba

Forum Moderator, 1805 Posts

31 May 2012 at 3:38am

Hi sb,

you can do...

<% include TemplateName %>

however when it comes to parameters you don't need them because the included template will be int he same context as the one you are calling it from so it still has the same access to build in page controls or if in a different context (e.g. you used control MyObject).

Here is some more info on the templates... however best to go through the tutorials to get the best idea...
http://doc.silverstripe.org/sapphire/en/topics/templates
http://doc.silverstripe.org/sapphire/en/reference/advanced-templates