Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » <% control %> to list only certain type of sub pages

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

Page: 1
Go to End
Author Topic: 2050 Views
  • mark-e-mark
    Avatar
    Community Member
    9 Posts

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

    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?

  • mark-e-mark
    Avatar
    Community Member
    9 Posts

    Re: <% control %> to list only certain type of sub pages Link to this post

    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>

  • Blake_NiteoDesign
    Avatar
    Community Member
    17 Posts

    Re: <% control %> to list only certain type of sub pages Link to this post

    Sweet! Thanks for posting the answer!

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