Snippet: Template logic to fetch and group results by letter


I am using fetch and need to use a view_parameter to filter the data ...

Sort. I need to sort the items by first letter (a , b , c , d ...)

Group. I need the items 'grouped' by letter

<awormus> and I didn't want to do a "first letter" attribute which would have been silly :)


Try using the alphabet navigator features added in 3.9

I prefer this solution these days rather than more custom code.

Another Answer

Yet Another Answer

{def $items = fetch( 'content', 'list', 
 hash( parent_node_id, $node.node_id,'sort_by', array( 'name', true() )) ) } 
 {foreach $items as $item}
 {if $item.data_map.term_term.value|begins_with($view_parameters.view)}
 <span class="subheaders">{$item.data_map.term_term.value}: </span>
 <span class="content"> {$foo.data_map.term_description.value} </span>