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.

EE within if:elseif - what am I doing wrong?

April 12, 2011 2:23pm

Subscribe [4]
  • #1 / Apr 12, 2011 2:23pm

    jeremyvaught

    7 posts

    I have this code in a pages module page template:

    {if segment_1 == 'admissions'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="128" limit="1" cache="no"}
        {if:elseif segment_1 == 'academics'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="129" limit="1" cache="no"}
        {if:elseif segment_1 == 'faculty'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="130" limit="1" cache="no"}
        {if:elseif segment_1 == 'lifeatacu'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="133" limit="1" cache="no"}
        {if:elseif segment_1 == 'about'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="134" limit="1" cache="no"}
        {if:elseif segment_1 == 'athletics'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="142" limit="1" cache="no"}
        {/if}

    But it always give the first entry. My first try was:

    {exp:channel:entries dynamic="no" channel="landing-page" 
        {if segment_1 == 'admissions'}
             entry_id="128" 
        {if:elseif segment_1 == 'academics'}
             entry_id="129" 
        {if:elseif segment_1 == 'faculty'}
             entry_id="130" 
        {if:elseif segment_1 == 'lifeatacu'}
             entry_id="133"
        {if:elseif segment_1 == 'about'}
             entry_id="134" 
        {if:elseif segment_1 == 'athletics'}
             entry_id="142" 
        {/if}
     limit="1" cache="no"}

    And it always returns the last entry.

    The other part of it is that I can run the latter If statement independent of the channel:entried before and after the code in question and the results are correct, just not where it counts.

    Clearly I’m doing something wrong but I can’t figure out what.

    For what it’s worth, here is the entire page (including extra if statements to test:

    Begin IF
    <!-- for test purposes -->
        {if segment_1 == 'admissions'}
             entry_id="128" 
        {if:elseif segment_1 == 'academics'}
             entry_id="129" 
        {if:elseif segment_1 == 'faculty'}
             entry_id="130" 
        {if:elseif segment_1 == 'lifeatacu'}
             entry_id="133"
        {if:elseif segment_1 == 'about'}
             entry_id="134" 
        {if:elseif segment_1 == 'athletics'}
             entry_id="142" 
        {/if}
    
    End IF
    
    
        {if segment_1 == 'admissions'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="128" limit="1" cache="no"}
        {if:elseif segment_1 == 'academics'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="129" limit="1" cache="no"}
        {if:elseif segment_1 == 'faculty'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="130" limit="1" cache="no"}
        {if:elseif segment_1 == 'lifeatacu'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="133" limit="1" cache="no"}
        {if:elseif segment_1 == 'about'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="134" limit="1" cache="no"}
        {if:elseif segment_1 == 'athletics'}
            {exp:channel:entries dynamic="no" channel="landing-page" entry_id="142" limit="1" cache="no"}
        {/if}
    
    <nav class="grid_5">
    <h2 class="subnav-header">{title}</h2>
        <ul class="subnav">
            {lp_subnavigation}<!-- this is a matrix loop -->
            <a href="http://{link}class=subnav-button"><li>{title}</li></a>
            {/lp_subnavigation}
        </ul>
    </nav>
    <!-- for test purposes -->
    channel = {channel}
    
    segment_1 = {segment_1}
    
    entry_id = {entry_id}
    
    
    
    Begin IF
    
        {if segment_1 == 'admissions'}
             entry_id="128" 
        {if:elseif segment_1 == 'academics'}
             entry_id="129" 
        {if:elseif segment_1 == 'faculty'}
             entry_id="130" 
        {if:elseif segment_1 == 'lifeatacu'}
             entry_id="133"
        {if:elseif segment_1 == 'about'}
             entry_id="134" 
        {if:elseif segment_1 == 'athletics'}
             entry_id="142" 
        {/if}
    
    End IF
    {/exp:channel:entries}

    Bottom line what I need is there are pages, so example.com/faculty the code works great. But at example.com/faculty/nextlevel I’m trying to get the nav to act like if it was back one level.

  • #2 / Apr 12, 2011 5:26pm

    jeremyvaught

    7 posts

    All right, it’s a HORRIBLE solution, but it’s all I can get to work. There HAS to be a better way to do this…

    What is the opposite of DRY?

    {if segment_1 == 'admissions'}
        {exp:channel:entries dynamic="no" channel="landing-page" entry_id="128"  limit="1" cache="no"}
            <nav class="grid_5">
                <h2 class="subnav-header">{title}</h2>
                <ul class="subnav">
                    {lp_subnavigation}
                        <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                    {/lp_subnavigation}
                </ul>
            </nav>
        {/exp:channel:entries}
    {if:elseif segment_1 == 'academics'}
        {exp:channel:entries dynamic="no" channel="landing-page" entry_id="129"  limit="1" cache="no"}
            <nav class="grid_5">
                <h2 class="subnav-header">{title}</h2>
                <ul class="subnav">
                    {lp_subnavigation}
                        <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                    {/lp_subnavigation}
                </ul>
            </nav>
        {/exp:channel:entries}
    {if:elseif segment_1 == 'faculty'}
        {exp:channel:entries dynamic="no" channel="landing-page" entry_id="130"  limit="1" cache="no"}
            <nav class="grid_5">
                <h2 class="subnav-header">{title}</h2>
                <ul class="subnav">
                    {lp_subnavigation}
                        <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                    {/lp_subnavigation}
                </ul>
            </nav>
        {/exp:channel:entries}
    {if:elseif segment_1 == 'lifeatacu'}
        {exp:channel:entries dynamic="no" channel="landing-page" entry_id="133" limit="1" cache="no"}
            <nav class="grid_5">
                <h2 class="subnav-header">{title}</h2>
                <ul class="subnav">
                    {lp_subnavigation}
                        <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                    {/lp_subnavigation}
                </ul>
            </nav>
        {/exp:channel:entries}
    {if:elseif segment_1 == 'athletics'}
        {exp:channel:entries dynamic="no" channel="landing-page" entry_id="142"  limit="1" cache="no"}
            <nav class="grid_5">
                <h2 class="subnav-header">{title}</h2>
                <ul class="subnav">
                    {lp_subnavigation}
                        <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                    {/lp_subnavigation}
                </ul>
            </nav>
        {/exp:channel:entries}
    {if:elseif segment_1 == 'about'}
        {exp:channel:entries dynamic="no" channel="landing-page" entry_id="134"  limit="1" cache="no"}
            <nav class="grid_5">
                <h2 class="subnav-header">{title}</h2>
                <ul class="subnav">
                    {lp_subnavigation}
                        <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                    {/lp_subnavigation}
                </ul>
            </nav>
        {/exp:channel:entries}
    {/if}
  • #3 / Apr 13, 2011 12:22am

    Cheif

    626 posts

    I dont know why ur using hard coded ID’s because that is going to cause a world of hurt at some stage, but try using an embed:

    {if segment_1 =="XXX"}
    {embed="templategroup/template" theID="123"}
    {if:elseif segment_1 =="YYY"}
    {embed="templategroup/template" theID="124"}
    //continue
    {/if}
    
    //Embed template
    {exp:channel:entries dynamic="no" channel="landing-page" entry_id="{embed:theID}" limit="1" cache="no"}
    <nav class="grid_5">
            <h2 class="subnav-header">{title}</h2>
            <ul class="subnav">
                {lp_subnavigation}
                   <a href="http://{link}class=subnav-button"><li>{title}</li></a>
                {/lp_subnavigation}
            </ul>
        </nav>
    {/exp:channel:entries}
  • #4 / Apr 13, 2011 6:45am

    John Henry Donovan

    12339 posts

    Excellent Cheif 😊

    Does that help you jeremy?

  • #5 / Apr 18, 2011 11:03pm

    Hop Studios

    481 posts

    You can also try using simple IF statements:

    {exp:channel:entries dynamic="no" channel="landing-page" 
        {if segment_1 == 'admissions'}
             entry_id="128" 
        {/if}
        {if segment_1 == 'academics'}
             entry_id="129" 
        {/if}
        {if segment_1 == 'faculty'}
             entry_id="130" 
        {/if}
        {if segment_1 == 'lifeatacu'}
             entry_id="133"
        {/if}
        {if segment_1 == 'about'}
             entry_id="134" 
        {/if}
        {if segment_1 == 'athletics'}
             entry_id="142" 
        {/if}
     limit="1" cache="no"}
  • #6 / Apr 19, 2011 4:03pm

    Brandon Jones

    5500 posts

    Thanks Hop Studios.

    How are you coming along with this, jeremyvaught?

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

ExpressionEngine News!

#eecms, #events, #releases