Group Company Directory items in alphabetical order and add shortcuts
Previous article Next articleThe Company Directory module is good to show an overview of companies and contacts at your CMS Made Simple™ website.
With a little adjustment to the summary template you can group the output in alphabetical order and add shortcuts to the entries.
How to use
Add to the top of your summary template:
{$initial = ''}
{$stored_initial = ''}
<p><b>Directly to initial: </b>
{foreach from=$items item=entry}
{if $entry->company_name[0]|lower != $initial}
{$initial = $entry->company_name[0]|lower}
<b><a href="{$page_alias}#{$initial}">{$initial|upper}</a></b>
{/if}
{/foreach}
</p>
{$stored_initial = ''}
<p><b>Directly to initial: </b>
{foreach from=$items item=entry}
{if $entry->company_name[0]|lower != $initial}
{$initial = $entry->company_name[0]|lower}
<b><a href="{$page_alias}#{$initial}">{$initial|upper}</a></b>
{/if}
{/foreach}
</p>
And add directly after the {foreach ...} 5 new lines:
{if isset($items)}
{foreach from=$items item=entry}
{if $entry->company_name[0]|lower != $stored_initial}
<a name="{$entry->company_name[0]|lower}"></a>
<h3>{$entry->company_name[0]|upper}</h3>
{$stored_initial = $entry->company_name[0]|lower}
{/if}
<article class="CompanyDirectoryItem" style="padding-bottom: 2em;">
<div class="row">
...
...
{/foreach}
{/if}
{foreach from=$items item=entry}
{if $entry->company_name[0]|lower != $stored_initial}
<a name="{$entry->company_name[0]|lower}"></a>
<h3>{$entry->company_name[0]|upper}</h3>
{$stored_initial = $entry->company_name[0]|lower}
{/if}
<article class="CompanyDirectoryItem" style="padding-bottom: 2em;">
<div class="row">
...
...
{/foreach}
{/if}
Working example
Comment Form
ReviewManager
ReviewManager
0 Comments
No comments yet...