Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Repeating HTML structure for different includes

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 523 Views
  • sb
    Avatar
    Community Member
    2 Posts

    Repeating HTML structure for different includes Link to this post

    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

  • sb
    Avatar
    Community Member
    2 Posts

    Re: Repeating HTML structure for different includes Link to this post

    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 ...

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Repeating HTML structure for different includes Link to this post

    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

    523 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.