0

I'm having a bit of trouble with getting Stash to change a variable. I'm using it to output a heading in search results when it's not the same as the last result. Here is my code:

{!-- Set the sorthead variable to something random --}
{exp:stash:set name="sorthead"}flibberdigibbet{/exp:stash:set}

{exp:low_search:results
    channel="magazine-articles"
    status="not closed"
    limit="10"
    paginate="both"
    disable="member_data|category_fields"
    category="1"
    orderby="articles-sorthead"
    sort="asc"
 }

      {!-- check the variable before setting --}
      before: {exp:stash:get name='sorthead'}

      {!-- output heading if it's not  the same as the last one --}
      {if "{exp:stash:get name='sorthead'}" != "{articles-sorthead}"}
          <h2>{articles-sorthead}</h2>
      {/if}

      {!-- set the variable so that next time we can check again
           THIS IS NOT HAPPENING FOR SOME REASON --}
      {exp:stash:set name="sorthead"}{articles-sorthead}{/exp:stash:set}

      {!-- check it has worked --}
      after: {exp:stash:get name='sorthead'}
{/exp:low_search:results}

So I don't really know what is going on, but both before and after output as 'flibberdigibbet' and the setting never seems to happen the second time. unless the first set is happening on every loop of the low search tag - but I don't think it should be!

Hope you can help!

2
  • 1
    You plugin with the same parameters. So ee most probably cached it. Try to add random {exp:stash:set name="sorthead" random} or change name
    – Max Lazar
    Dec 10 '14 at 10:32
  • @MaxLazar awesome, thanks! the random param worked. You should add your comment as a reply so I can mark it as the answer :)
    – Joe Beaver
    Dec 10 '14 at 11:08
4

You use plugin with the same parameters. So EE cached it.

Try to add random

{exp:stash:set name="sorthead" random} {/exp:stash:set}

or change name.

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.