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 /

<% control %> to list only certain type of sub pages


Reply


3 Posts   2236 Views

Avatar
mark-e-mark

Community Member, 9 Posts

9 April 2010 at 3:07am

Edited: 09/04/2010 3:36am

First let me say that I'm new to SilverStripe - so there is probably a really simple answer to this that I just can't quite find.

Imagine I have a holder: AnimalHolder

Each AnimalHolder can hold multiple pages of types: CatPage or DogPage

What I want to achieve is to have two separate lists of Cats and Dogs in my AnimalHolder.ss.

I've tried similar to:

<ul id="cats">
<% if ClassName = CatPage %>
<% control Children %>
<li>Cat: $Title</li>
<% end_control %>
<% end_if %>
</ul>

<ul id="dogs">
<% if ClassName = DogPage %>
<% control Children %>
<li>Dog: $Title</li>
<% end_control %>
<% end_if %>
</ul>

however, this does not work.

Any ideas?

Avatar
mark-e-mark

Community Member, 9 Posts

9 April 2010 at 3:24am

Edited: 09/04/2010 3:36am

Ok .. I just figured it out myself. I need to control the Children first, then check ClassName ...

For posterity and the sake of others that may be similarly struggling, the following worked for me:

<ul id="cats">
<% if Children %>
<% control Children %>
<% if ClassName = CatPage %>
<li>$Title</li>
<% end_if %>
<% end_control %>
<% end_if %>
</ul>

<ul id="dogs">
<% if Children %>
<% control Children %>
<% if ClassName = DogPage %>
<li>$Title</li>
<% end_if %>
<% end_control %>
<% end_if %>
</ul>

Avatar
Blake_NiteoDesign

Community Member, 17 Posts

21 July 2010 at 3:57pm

Sweet! Thanks for posting the answer!