0

Having some issues here, not sure if it's even possible.

Template one lists one entry. I want to set a variable and make its name the entry_id of that entry, to be used to validate on the next template based on the same entry.

Template two, I want to match a url segment to the variable. But i need to get the variable name from that same entry, so need to use the {entry_id} in the stash get tag.

I am getting funny results, where it only works if the {entry_id} tag apears anywhere inside the channel:entries loop. If i remove that single tag then the conidional always fails.

I am using EEv2.9.2 and Stash 2.5.8

My code:

Template One:

{exp:channel:entries channel="whitepapers" url_title="{segment_3}" limit="1" disable="categories|member_data|pagination" parse="inward"}

{exp:stash:set_value name="{entry_id}" value="{current_time format="%d%Y%g%i%s"}" scope="user" save="yes"}    

{/exp:channel:entries}

Template Two:

        {exp:channel:entries channel="whitepapers" url_title="{segment_3}" dynamic="no" limit="1" disable="categories|member_data|pagination" parse="inward"}

        {exp:stash:parse process="end"}

        {if "{segment_5}" == "{exp:stash:get name='{entry_id}'}"}
        success
        {/if}

    {/exp:stash:parse}

    {exp:stash:parse process="end"}

        {if "{segment_5}" != "{exp:stash:get name='{entry_id}'}"}
        fail
        {/if}

    {/exp:stash:parse}

{!-- ALWAYS FAIL'S UNLESS THE {entry_id} TAG APPEARS IN THIS CHANNEL ENTRIES LOOP ANYWHERE --}

        {/exp:channel:entries}  

1 Answer 1

0

Try adding scope="user" to your stash:get:

{if segment_5 == "{exp:stash:get name='{entry_id}'}"}

(Don't think you need to add quotes & brackets for segment_5 for 2.9+, or parse="inward" for your outer channel:entries.)

If that doesn't work, also try without wrapping with stash:parse, or at least take off the process="end" so that the conditional is parsed inline instead.


UPDATE:

Version 1 or 2 below should work. The first grabs the stash variable but doesn't output it, so it's available for the conditionals. The second is if you use Switchee.

{exp:channel:entries 
    channel="whitepapers" 
    url_title="{segment_3}" 
    dynamic="no" 
    limit="1" 
    disable="categories|member_data|pagination"
}

    {!--version 1:--}
    {exp:stash:get name='{entry_id}' scope='user' output="no"}

    {if segment_5 == "{exp:stash:get name='{entry_id}'}"}
        success
    {/if}

    {if segment_5 != "{exp:stash:get name='{entry_id}'}"}
        fail
    {/if}

    {!--version 2:--}
    {exp:switchee variable="stash:{entry_id}" parse="inward"}
        {case value="{segment_5}"}
            match
        {/case}
        {case default="yes"}
            no match 
        {/case}    
    {/exp:switchee}

{/exp:channel:entries}
3
  • Hi, thanks, I tried all of the above with no avail. Very odd indeed.
    – Mark
    Oct 8, 2014 at 16:01
  • See if the updated answer helps. Oct 8, 2014 at 16:44
  • Cheers that worked, I originally had the stash:get you added into in version 1, I just didn't think to add output="no" to hide it. Thanks for pointing me in the right direction!
    – Mark
    Oct 9, 2014 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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