Jump to:

3432 Posts in 1025 Topics by 865 members

Template Questions

SilverStripe Forums » Template Questions » adding includes dynamically

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

Page: 1
Go to End
Author Topic: 1160 Views
  • spierala
    Avatar
    Community Member
    80 Posts

    adding includes dynamically Link to this post

    Hello all,

    I have a teaser section on many pages, including 4 teaser boxes next to each other. There will be many different teaser boxes and the editor of the site should be able to select in the backend which teaser boxes should be shown in the frontend.

    I had the idea to create the teaser boxes as template files in the Includes Folder. Then somehow make the names of the teaser ss.Files selectable via checkboxes in the backend for each Page. Then I would need some logic to check which teaser boxes should be shown. But the most important thing is to know how I can add includes dynamically in the template.

    Is this a general good idea or should I try to write widgets?

    many thanks,
    florian

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: adding includes dynamically Link to this post

    Hello Florian,

    the templates are the "view" part of MVC. To do this you should create a controller method.Why don´t you just upload images.

  • spierala
    Avatar
    Community Member
    80 Posts

    Re: adding includes dynamically Link to this post

    hello baba-papa!

    there should be actually different types of teaser boxes. one box contains news managed via the cms, other boxes contain swfs or images.

    now I try this: every teaser has a type set in the backend. Then the frontend checks for the type:

    <% control Teaser %>
       <% if TeaserType = News %>
          <% include NewsTeaser %>
       <% else %>   
          <div class="teaserItem">
             <div class="teaserHeader">
                <h3>$Header</h3>
             </div>
          </div>
       <% end_if %>
    <% end_control %>

    the only problem then is that the NewsTeaser is not getting its data anymore. I think this is because NewsTeaser is included in a control. Including the NewsTeaser after the control works fine and the News are shown correctly. I know to use $Top to access variables at top level. But this does not work in a control like <% control Top.News %>. MMh.

    NewsTeaser.ss looks like this:

    <div id="NewsTeaser">
    <div class="teaserItem">
       <div class="teaserHeader">
          <h3>News</h3>
          <% control News %>
             <p> $Header </p>
          <% end_control %>
       </div>
    </div>
    </div>

    Thanks,
    Florian

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: adding includes dynamically Link to this post

    Why don't you just create widgets? Sounds like basically what you're looking for.

  • spierala
    Avatar
    Community Member
    80 Posts

    Re: adding includes dynamically Link to this post

    heee Hamish! widgets sound great. thats actually the thing i need. but i´m just running into this problem:
    http://silverstripe.org/widgets-2/show/278535#post278535%23post278535

    florian

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