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.

Customising the CMS /

Alphabetic grouping of child pages


Reply


4 Posts   1479 Views

Avatar
craesh

Community Member, 25 Posts

10 July 2009 at 2:06am

Edited: 10/07/2009 2:08am

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

Avatar
craesh

Community Member, 25 Posts

13 July 2009 at 7:50pm

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

Avatar
Willr

Forum Moderator, 5513 Posts

13 July 2009 at 10:31pm

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 %>

Avatar
Stefdv

Community Member, 110 Posts

17 November 2010 at 1:35am

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