Snippet: Template logic to fetch and group results by letter

Question

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 :)

Answer

Try using the alphabet navigator features added in 3.9

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

Another Answer

http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/keyword

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)}
 <div>
 <span class="subheaders">{$item.data_map.term_term.value}: </span>
 <span class="content"> {$foo.data_map.term_description.value} </span>
 </div>
 {/if}
 {/foreach}