4

I am using the store finder module, and am trying to insert a "title" for each "state". If I have 20 stores in a certain state, I would only like to display the "title" once. Is there any way this could be done with an if statement? to kind of break the loop?

{exp:store_locator:stores}                       
<ul>
        <li style="width:260px; padding-right:20px; float:left; height:100px;">
            <h5>{name}</h5>

            {if address_line1 !=""}         
            {address_line1}<br/>
            {/if}

            {city}, {state} 
            {postal_code}<br />

            {if phone != ""}
            <strong>Phone:</strong> {phone}
            <br/>
            {/if}

            {if url != ""}
            <strong>Website:</strong> <a href="http://www.{url}" target="_blank">{url}</a>        <br/>
            {/if}
        </li>
    </ul>

    {/exp:store_locator:stores}
4
  • Try this, {if count == 1}{state}{/if}. – Justin Clarke Nov 11 '13 at 16:04
  • Unfortunately count=="1", only brings in the very first state. – Funkefied Nov 11 '13 at 18:47
  • I'm a little confused, by "title" for each "state" you mean the title is the name of the state? You're trying to list the stores by State but only show the state once? – notacouch Nov 13 '13 at 19:32
  • Correct. I'm trying to add a heading with the state name. Problem being it's in a loop, and it gives the heading above every store. I guess I need a way for the heading with {state} to not duplicate on loop. – Funkefied Nov 13 '13 at 19:47
2

There is an add-on from EE Garage that I have used to do that on a store finder before.

It's called NSM Channels. http://ee-garage.com/nsm-channels

Not sure if there is something similar on Devot-ee.com for free, but I know this works.

0
2

You can use stash lists. Store the state separately. On output order by the unique states and use a nested get_list to get the entries/stores per state.

(example from Croxton slide: Stash core principles )

{exp:stash:set_list name="my_stores" parse_tags="yes" scope="site"}
  {exp:store_locator:stores}
    {stash:item_state}{state}{/stash:item_state}
    {stash:item_name}{name}{/stash:item_name}
    {stash:item_info}
        {address_line1}<br>
        {city}, {state}<br>
        {postal_code}
    {/stash:item_info}
  {/exp:store_locator:stores}
{/exp:stash:set_list}

Then retrieve the unique states, and accompanying stores via:

{exp:stash:get_list name="my_stores" orderby="item_state" unique="item_state" scope="site"}
  <h2>{item_state}</h2>
  {exp:stash:get_list:nested name="my_stores" orderby="item_name" scope="site"
    match="#^{item_state}$#" 
    against="item_state"
    prefix="result"}
      <h3>{result:item_name}</h3>
      {result:item_info}
  {/exp:stash:get_list:nested}
{/exp:stash:get_list}

Note: if you use conditionals, like in your example for address_line1, etc., i'ld suggest adding the parameter parse_conditionals="yes" in set_list.

2
1

I think you'll need to enable PHP in the template, set it to parse on input and use it to store the value of {state} on each iteration of the loop, at the top of the loop check to see if state is equal to itself or not, if not the write out the value as a heading. :)

It's possible you might be able to achieve the same result with Stash but I'm not really familiar with that. :)

1
  • Awesome! i'll give it a shot and report back, thanks. – Funkefied Nov 13 '13 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.