ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[SOLVED] Seeking proper syntax for writing a conditional that checks if a stash variable is set. If true - display the stash variable.

December 09, 2011 4:41pm

Subscribe [3]
  • #1 / Dec 09, 2011 4:41pm

    BobbyAdamson

    1 posts

    Hello everyone, I’m an EE newbie so I apologize if I’m missing something crucial or using the wrong terminology. Here’s my issue:

    1.) I am using stash to create a stash variable called “test” if a specific channel field is set (lp_cta). I want to run a conditional in my sidebar layout after my entries channel is closed to say if that stash variable is set (test) then display it. If that variable is NOT set, I want it to display some other default message. I am able to get the stash variable to display outside of the conditional, but I cannot write the conditional so anything within it displays.

    2.) Here is my code
    This stores the stash variable

    {if lp_cta}{exp:stash:set name="test"}{lp_cta}{/exp:stash:set}{/if}

    This displays it without a conditional after the channel is closed. This is functional and does what is expected

    {exp:stash:get name="test"}

    I am not sure how to write the conditional. If you can make sense of what I’m trying to do with this maybe I can get some suggestions.

    {if stash:test}{exp:stash:get name="test"}{/if}

    3.) I am using EE v2.3.1

    Thank you.

  • #2 / Dec 09, 2011 10:07pm

    Justin Long

    196 posts

    Maybe try

    {if {exp:stash:not_empty name="test"}}
        {test}                               
    {/if}

    Some Modules and plugins require some weird conditional syntax especially with quotes and curly braces. I do not know exactly what causes that but I have a general rule of thumb when I am developing a site if I have a conditional that is not showing up for some reason to try adding quotes or curly braces around it to see if that fixes the problem.

  • #3 / Dec 10, 2011 4:47pm

    Michael Rog

    179 posts

    Adding quotes to force the direct string comparison frequently solves my template-conditional issues:

    {if "{exp:some_plugin}" == "some_value"} ... {/if}

     

  • #4 / Dec 12, 2011 3:03pm

    BobbyAdamson

    1 posts

    Thanks gentlemen! I used Justin’s fix and it worked great. I’ll keep the quote solution in mind for the future.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases