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 /

adding includes dynamically


Reply


5 Posts   1201 Views

Avatar
spierala

Community Member, 80 Posts

3 February 2010 at 5:27am

Edited: 03/02/2010 5:28am

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

Avatar
baba-papa

Community Member, 279 Posts

3 February 2010 at 12:07pm

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.

Avatar
spierala

Community Member, 80 Posts

3 February 2010 at 10:42pm

Edited: 03/02/2010 10:43pm

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

Avatar
Hamish

Community Member, 712 Posts

6 February 2010 at 6:08pm

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

Avatar
spierala

Community Member, 80 Posts

8 February 2010 at 10:45am

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