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.

Conditionals comparing session value to static value

June 03, 2011 10:28pm

Subscribe [2]
  • #1 / Jun 03, 2011 10:28pm

    ks808

    12 posts

    I have a problem with conditionals not working with a snippet value.

    First, a session is set with one of two values; “HWN” or “ENG” using the “session_variables” plug-in.

    Second, a snippet is defined using the get method from the “session_variables” plug-in, like so:
    “Snippet Name”: k_lang
    “Variable Content”: {exp:session_variables:get name='k_lang'}

    Third, when I view the page containing the following conditional, it doesn’t seem to work.  Here is the conditional statement from the template:
    {if {k_lang} ==‘HWN’ }
      <<display this>>
    {if:else}
      <<display that>>
    {/if}

    If I hit the template with the above EE tags, it always evaluates to <<display that>>.  If I replace the snippet value with a static string of “HWN”, then it evaluates to <<display this>>, which is the correct outcome.

    I have tested if the snippet value is being parsed by EE by just echo’ing out {k_lang} in the template…which it does. I also ran the value through a plug-in that uses PHP’s trim function to strip any invisible characters.

    Any ideas why the conditional doesn’t behave in an expected way?  Thanks!

  • #2 / Jun 03, 2011 10:58pm

    ks808

    12 posts

    Ok, I just used PHP to evaluate the conditional and it worked.

    For the curious, this is what I did:
    - Enabled PHP and set to Output in preferences for the template.
    - Set PHP variable to EE value for evaluation
    - Set the display variables in PHP since EE tags will be parsed before PHP tags
    - Then evaluated the PHP value against the static values using PHP conditionals
    - mission accomplished!

    Still not sure why an all EE conditional didn’t work…which i’d rather have done.  If anyone can shed some light on this, it may help me in the future.  Thanks!

  • #3 / Jun 06, 2011 4:42am

    John Henry Donovan

    12339 posts

    ks808,

    The issue here is wit the parse order of the template. You could try simple conditionals to see if that would work for you as they are parsed sooner.

    {if "{k_lang}" == "HWN"}
      <<display this>>
    {/if}
    {if "{k_lang}" != "HWN"}
      <<display that>>
    {/if}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases