Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Alphabetic grouping of child pages

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

Page: 1
Go to End
Author Topic: 1371 Views
  • craesh
    Avatar
    Community Member
    25 Posts

    Alphabetic grouping of child pages Link to this post

    Hi!

    I'm designing a website that will have some pages containing a greater amount of subpages (up to 150 subpages per page - no way to split that up). The idea is to group the list of subpages by their first character, just like the categories in Wikipedia are displayed.

    I've created a new model that will hold that subpages, having control that will output a list of all occuring first characters. So

    <% control get_alphabet %>
    <a href="#$char">$char</a>
    <% end_control %>

    in it's template will give me a heading navigation bar. Now I want the titles of all subpages to show up below their first character. The output should be like

    <a name="A"/>
    <h2>A</h2>
    <ul>
    <li><a href...>Alien</a></li>
    <li><a href...>Argon</a></li>
    <li><a href...>Automobile</a></li>
    </ul>

    <a name="B"/>
    <h2>B</h2>
    <ul>
    <li><a href...>Butterfly</a></li>
    ...

    But the following code won't work:

    <% control get_alphabet %>
    <a name="$char"/>
    <h2>$char</h2>
    <ul>
    <% control get_children_for_char($char) %>
    <li><a href...>$Title</a></li>
    <% end_control %>
    </ul>
    <% end_control %>

    I get an error in this template. If I take out the second control statement or put in a constant parameter, it won't complain. I guess, I cannot pass a variable parameter to a control block, like "get_children_for_char($char)"? How would I manage that? Are there alternatives?

    Thanks and greatings!
    craesh

  • craesh
    Avatar
    Community Member
    25 Posts

    Re: Alphabetic grouping of child pages Link to this post

    Hi again!

    I would appreciate any comments/ideas on this issue. This would be also interesting for other people, as it's not a uncommon feature/behavior.

    Thanks!
    craesh

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Alphabetic grouping of child pages Link to this post

    The template parser does not support passing vars - <% control get_children_for_char($char) %>.

    You would have to do this in PHP and return your own dataobject set

    function ArticlesOrders() {
    $abc = array('A','B','C'); // get alphabet
    $output = new DataObjectSet(); // output;
    foreach($abc as $char) {
    $articles = // write a dataobjectget which gets it on the char
    $output->push(new ArrayData(array(
    'Char' => $char,
    'Articles' => $articles
    ));
    }
    return $output;

    In your template

    <% control ArticlesOrders %>
    $Char
    <% control Articles %>.....<% end_control %>
    <% end_control %>

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: Alphabetic grouping of child pages Link to this post

    Willr,

    I know it's an old post, but i'm in need of exactly the same functionality.
    I have gone through the recipe http://doc.silverstripe.org/recipes:alphabetical_dataobjectset , but i'm not sure how to implement it exactly.

    It doesn't give me any output on my page.

    I could really use an extended example.

    tx in advance

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