A-Z Format for listing

What is the best way to achieve a result listing layout in an A-Z style. For example:

A
Accounting
Art

B
Business
Business and Enterprise

and so on.

Is that possible using Funnelback? Was looking at Tierbars but this seem to only handle event start dates.

Hi @gavin1211 -

I’m assuming the results are at least appearing in the desired order (you’re using sort=title or similar already), and you’ve got a dedicated form or code block focused on this sorting scenario. Funnelback defaults to case-insensitive indexing and sorting.

A Freemarker snippet should assist in this case - here’s an example to get you started:

<#assign currentLetter = "a">
${currentLetter?upper_case}
<@s.Results>
    ...
    <#-- Print A-Z tier -->   
    <#if result.title?lower_case?starts_with(currentLetter)>
      <#assign currentLetter = result.title?substring(0, 1)}>
      ${currentLetter?upper_case}
    </#if>

    <#-- Print result -->
    ${result.title}
    ...
</@s.Results>

There’s other variations worth considering, too - sometimes a canonical title will not be the one preferred for sorting (e.g. “Moby Dick”, or “The Whale”, or “Whale, The”), sometimes you may not want to output a letter tier for which there are no matching titles.

Refer also:

http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_starts_with
http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_lower_case
http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_upper_case
http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_substring

1 Like

Hi Gavin,

The knowledge base has an article on how to produce an A-Z listing:

cheers,
Peter

1 Like