Group Company Directory items in alphabetical order and add shortcuts

  Previous article Next article  

Group Company Directory items in alphabetical order and add shortcuts

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.5
  Last updated: 22-11-2017
  Comments: 0
  http://cms.ms/JkSH

The Company Directory module is great to show a survey 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>&nbsp;
  {/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}

  Working example





CMS Made Simple 2.2.5 - Tutorials, tips and tricks - CMSMS 2.2.5

Group Company Directory items in alphabetical order and add shortcuts

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.5
  Last updated: 22-11-2017
  Comments: 0
  http://cms.ms/JkSH