1

I have this code

{exp:channel:entries channel="katalog" limit="12" dynamic="yes" status="open" show_future_entries="no" orderby="date" sort="desc" disable="member_data" pagination="bottom"}

{!-- if entry has one of those three categories then set variable link to true --}
{categories show="51|50|39"}
      {exp:stash:set_value name="link" value="true"}
{/categories}

{if "{exp:stash:get name='link'}" == "true"}
//then print content1
{if:else}
//print content2
{/if}

{!-- delete stash variable and go for next loop because channel entries will do this 12 times --}
{exp:stash:unset name="link"}

{/exp:channel:entries}

what happens is this. If first entry in pagination has some category, then stash variable will be set to true for all 12 entries shown on that pagination page. Likewise, if first entry does not have any category added to itself then variable link will not be set to "true" and other part of if condition will be displayed.

How to make stash to overwrite it's values ... what am I doing wrong? I need categories for this problem, but I am not sure what else to use.

1

You probably don't need to use stash in this case, and could test if in the categories within the conditional:

{if "{categories show='51|50|39' limit='1'}yes{/categories}" == "yes"}
    //then print content1
{if:else}
    //print content2
{/if}

Another variation is to use a category count plugin in the same way (in place of the native categories tags above).

  • That is wonderful. This workaround is what I was looking for for some time now. Romans, you are my hero :D thank you. I cannot vote up but thank you thank you. Never thought of this solution. – BSheep May 4 '15 at 19:45

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.