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.

Entry variables in conditional statements

September 26, 2012 12:01am

Subscribe [2]
  • #1 / Sep 26, 2012 12:01am

    boomer42025

    14 posts

    Greetings,

    Is this possible to do…

    I’m looping through entries based on the category they are in.  When it reaches the entry titled “What We Do”, I want it to process the code in the if statement.  How can I use the {title} variable in the entries tag in my if statement?  I know for sure one of the entries in the loop is titled “What We Believe”, but it doesn’t show up under the entry titled “What We Believe” on output.

    {exp:channel:entries category="13" dynamic="no"}
      {title}

    {if "{title}” == “what we believe”} 
    do this….
    {/if}

    {/exp:channel:entries}

    Thanks in advance

  • #2 / Sep 26, 2012 1:50am

    FiSt

    40 posts

    Try this:

    {exp:channel:entries category='13' dynamic='no'}
    {if title == 'What We Believe'}  
    do this….
    {/if}
    {/exp:channel:entries}
  • #3 / Sep 26, 2012 8:30pm

    boomer42025

    14 posts

    Thanks for the response.

    Thanks, this is a step closer to what I was trying to accomplish.  I tweaked the code, and here is what I got now.


    {exp:channel:entries category='13' dynamic='no'}
      {title}
    {if title == segment_2} 
    do this
    {/if}
    {/exp:channel:entries}

    This code is being used to create a side menu.  It is cycling through all the entries assigned to the About Category like I want it to.  And now it does show the “do this” text under the menu item ‘What We Believe’.  The problem I now have is that I only want the “do this” to show if the {title} is equal to {segment_2} of the url.  The “do this” will eventually be a submenu under “What We Do”, showing only if you are on the “What We Do” page.  I have a feeling I’m not using {segment_2} correctly in the if statement??

    Any suggestions??

    Thank you for your help!!

  • #4 / Sep 26, 2012 8:50pm

    boomer42025

    14 posts

    Well I did figure out a way to accomplish what I was trying to do.  The “do this” now only appears if you are on the “What We Believe” page.  Per code below…

    if:elseif segment_1==“about”}

    {exp:channel:entries category="13" dynamic="no"}
      {title}


    {if title}
    <?php
    $title = “{url_title}”;
    $page = “{segment_2}”;

    if (($page==“what-we-believe”) && ($title==“what-we-believe”)){
    ?>

    do this

    <?php
    }
    ?>

    {/exp:channel:entries}

    {/if}

    Any suggestions on doing this without PHP??

  • #5 / Sep 26, 2012 10:26pm

    DigitalDoctors

    76 posts

    Does this work for you?

    {exp:channel:entries category='13' dynamic='no'}
        {if url_title == segment_2}
            do this….
        {/if}
    {/exp:channel:entries}
  • #6 / Sep 27, 2012 12:32am

    FiSt

    40 posts

    Hello boomer42025. Could you please wrap your code in proper BB tag ?

    The same without PHP in template:

    {exp:channel:entries category='13' dynamic='no'}
         {if title && title == 'what-we-believe' && url_title == 'what-we-believe'}
               do this
         {/if}
    {/exp:channel:entries}

    Or

    {exp:channel:entries category='13' dynamic='no'}
         {if title && title == url_title}
               do this
         {/if}
    {/exp:channel:entries}

    Also, please read this topic to get more understanding of conditions:

  • #7 / Sep 27, 2012 11:08am

    Lisa Wess

    20502 posts

    boomer -

    I would strongly recommend comparing to the URL title, much like FiSt has recommended, but with a slight tweak:

    {exp:channel:entries category='13' dynamic='no'}
         {if url_title == segment_2}
              do this
          {/if}
    {/exp:channel:entries}

    No PHP needed at all, and it won’t be thrown if you have grammatical marks in your title since the URL title strips those already.

    Does that help?

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

ExpressionEngine News!

#eecms, #events, #releases