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.

Segment-based conditional not working.

September 25, 2010 6:21pm

Subscribe [4]
  • #1 / Sep 25, 2010 6:21pm

    Airtype Studio

    14 posts

    I’ve done this several times before, but for some reason it’s not working for me. Can someone find any reason why this wouldn’t work?

    Here’s the template:

    {if segment_3 == ''}
                <div id="content" class="perspectives">
                    <div id="left">
                        <h2>Perspectives</h2>
    <p>                    <div><br />
    {exp:channel:entries channel="perspectives" entry_id="56"}<br />
                            <h1>{title}</h1><br />
                    {exp:trunchtml chars="300" inline="..." ending="<a href='{path=site/comments}'>More »</a>"}{perspectives_body}{/exp:trunchtml}<br />
    {/exp:channel:entries}<br />
                        </div><br />
                    </div><br />
                    <div id="right"><br />
                        {site_url}images/photos/perspectives.jpg<br />
                    </div><br />
                    <div id="bottom"><br />
                        <div><br />
    {exp:channel:entries channel="perspectives" entry_id="57"}<br />
                            <h1>{title}</h1><br />
                    {exp:trunchtml chars="300" inline="..." ending="<a href='{path=site/comments}'>More »</a>"}{perspectives_body}{/exp:trunchtml}<br />
    {/exp:channel:entries}<br />
                        </div><br />
                        <div><br />
    {exp:channel:entries channel="perspectives" entry_id="58"}<br />
                            <h1>{title}</h1><br />
                    {exp:trunchtml chars="300" inline="..." ending="<a href='{path=site/comments}'>More »</a>"}{perspectives_body}{/exp:trunchtml}<br />
    {/exp:channel:entries}<br />
                        </div><br />
                    </div><br />
                </div><!--end content--><br />
                {if:else}<br />
                <div id="content" class="perspective"><br />
    {exp:channel:entries channel="perspectives" limit="1"}<br />
                    <h1>{title}</h1><br />
                    {perspectives_body}<br />
    {/exp:channel:entries}<br />
                </div><!--end content--><br />
                {/if}

    But whether or not I have anything in the third segment, it shows the page based on the “else” portion of the statement. See http://juisebox.com/fmg/index.php/insights/perspectives/. No third segment, but still only shows the title and body.

    I’ve tried setting it up several ways. I tried:

    {if segment_3}
    {if segment_3 != ''}

    I’ve also cleared all of my caches. Nothing. Any suggestions?

  • #2 / Sep 25, 2010 10:17pm

    ralph.m

    225 posts

    Hmm, I can’t see a problem with that EE code. I would recommend not using more than one H1 per page, though (unless you are using HTML5).

  • #3 / Sep 27, 2010 3:10am

    John Henry Donovan

    12339 posts

    Airtype Studio,

    Can you try using simple conditionals. Replace the following

    {if:else}
                <div id="content" class="perspective">
    {exp:channel:entries channel="perspectives" limit="1"}
                    <h1>{title}</h1>
                    {perspectives_body}
    {/exp:channel:entries}
                </div><!--end content-->
                {/if}

    with this

    {/if}
      {if segment_3 != ''} 
                <div id="content" class="perspective">
    {exp:channel:entries channel="perspectives" limit="1" url_title="{segment_3}"}
                    <h1>{title}</h1>
                    {perspectives_body}
    {/exp:channel:entries}
                </div><!--end content-->
                {/if}
  • #4 / Sep 27, 2010 11:24am

    Airtype Studio

    14 posts

    Hi,

    I found my problem this morning. Total user error. Thanks for the help, John.

    Marcus

  • #5 / Sep 27, 2010 3:52pm

    Ingmar

    29245 posts

    I am very glad to see you were able to solve this. Please post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases