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.

Condition confusion

November 09, 2012 11:59am

Subscribe [3]
  • #1 / Nov 09, 2012 11:59am

    Jason Turcotte

    102 posts

    I’m trying to create a template that will determine what content to show based on a conditional that evaluates segment_2.

    <!-- determine county -->
        {if "{segment_2}" == "belknap-county"}
        <!-- belknap county -->
        {exp:channel:entries channel="belknap_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "carroll-county"}
        <!-- carroll county -->
        {exp:channel:entries channel="carroll_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "cheshire-county"}
        <!-- cheshire county -->
        {exp:channel:entries channel="cheshire_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "coos-county"}
        <!-- coos county -->
        {exp:channel:entries channel="coos_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "grafton-county"}
        <!-- grafton county -->
        {exp:channel:entries channel="grafton_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "hillsborough-county"}
        <!-- hillsborough county -->
        {exp:channel:entries channel="hillsborough_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "merrimack-county"}
        <!-- merrimack county -->
        {exp:channel:entries channel="merrimack_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "rockingham-county"}
        <!-- rockingham county -->
        {exp:channel:entries channel="rockingham_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "stafford-county"}
        <!-- stafford county -->
        {exp:channel:entries channel="stafford_county_listings" dynamic="no"}
        
        {if:elseif "{segment_2}" == "sullivan-county"}
        <!-- sullivan county -->
        {exp:channel:entries channel="sullivan_county_listings" dynamic="no"}
        
        {if:else}
        <h2>Not sure what county you are looking for…</h2>
    <p>    {/if}<br />
        </p><h2>{title}</h2>
    <p>    {cty_page_content}<br />
        {/exp:channel:entries}

    The conditional appears to be working properly because I can see the comments in the code that indicate which branch of the statement was evaluated. The (very) confusing part is that no matter what branch evaluates as true, I get channel entries for the first channel only (meaning the “belknap_county_listings” channel).

    I’ve turned on template debugging and see the following, no matter what:

    (0.011003 / 11.74MB) Tag: {exp:channel:entries channel="belknap_county_listings" dynamic="no"}
    (0.011058 / 11.74MB) Closing Tag Found

    Any thoughts on why this would be happening? Can you not use the opening channels tag in a conditional statement? My thoughts are that it’s parsing the tag, regardless of the conditional.

  • #2 / Nov 11, 2012 10:30am

    Boyink!

    5011 posts

    Historically the logic has been that you can’t split up the channel:entries tag like that - the entire loop has be to within the conditional node.  Have you tested that?

    Alternatively, were it me I’d go back and rename my channels slightly so that I could just do:

    {exp:channel:entries channel="[segment_2}_listings" dynamic="no"}

    And avoid the conditionals altogether.

  • #3 / Nov 12, 2012 11:00am

    Shane Eckert

    7174 posts

    Hey there Jason,

    What do you think of Mike’s input? Sounds fantastic to me!

    Please let us know where things are at.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases