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.

conditional not picking up segment_2 empty

September 29, 2008 8:17am

Subscribe [1]
  • #1 / Sep 29, 2008 8:17am

    Giles Thurston

    34 posts

    Hi,

    I am writing some conditionals based upon the contents of different segments of the URL.  I used the example in the documentation as a starting point but it doesn’t appear to be working.  Regardless of whether there is a segment_2 in the URL or not it is still thinks there is.

    The am using the following code at the top of my template

    {if segment_2}
      {assign_variable:selected_year="{segment_2}"}
    {if:else}
      {assign_variable:selected_year="No year supplied"}
    {/if}

    Testing this with the URL’s http://www.mysite.com/template/ and www.mysite.com/template/2008.  In both cases it assigns either 2008 or am empty string to the select_year variable.  In the first example I would expect it to drop into the else case and assign “No year supplied”

    Has anybody else had problems like this?

    Cheers

    Giles

  • #2 / Sep 29, 2008 12:42pm

    Greg Aker

    6022 posts

    Giles:

    This works for me:

    {if segment_2 != ''}
      {assign_variable:selected_year="{segment_2}"}
    {/if}
    {if segment_2 == ''}
      {assign_variable:selected_year="No year supplied"}
    {/if}

    I hope that helps.

    -greg

  • #3 / Sep 29, 2008 7:52pm

    Giles Thurston

    34 posts

    Hi Greg,

    Yeah that’s what I ended up going with in the end.  May be worth updating the documentation as the code example doesn’t appear to work, at least not for me anyway :(

    Cheers

    Giles

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

ExpressionEngine News!

#eecms, #events, #releases