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.

If:else statement is freaking out 2.4.0

April 06, 2012 6:47pm

Subscribe [2]
  • #1 / Apr 06, 2012 6:47pm

    tpayton

    172 posts

    So I’ve got some code I use on pretty much all my sites and is not working in 2.4.

    {header_features}
           {if link}<li><a href="http://{link}">{label}</a></li>
              {if:elseif page} <li><a href="http://{page}">{label}</a></li>
              {if:else}<li>{label}</li>
          {/if}
       {/header_features}

    The if else statements just don’t seem to be working. The last if:else seems to be displaying no matter what. it is spitting out double or triple entries. Any thoughts?

     

  • #2 / Apr 06, 2012 7:51pm

    glenndavisgroup

    436 posts

    Hi tpayton,

    Have you tried the following:

    {header_features}
        {if "{link}" != ""}
           <li><a href="http://{link}">{label}</a></li>
        {if:elseif "{page}" != ""}
           <li><a href="http://{page}">{label}</a></li>
        {if:else}
           <li>{label}</li>
        {/if}
    {/header_features}

    Mike

  • #3 / Apr 09, 2012 11:57am

    Dan Decker

    7338 posts

    Hi tpayton,

    Did Mike’s suggestion get you sorted out?

    When using Advanced Conditionals in 2.4, we’ve tightened up the checks a bit, being explicit can yield more reliable results.

    Is there anything else I can assist you with?

    Cheers,

  • #4 / Apr 10, 2012 12:05pm

    tpayton

    172 posts

    Thanks Mike. Unfortunately that is yielding the same results.

    I’ve inclosed some screen shots of the field data (it a Matrix field), the results as rendered and also the rendered source:

    <ul id="header_feature_list">
          
          <li>505-346-4673</li>
          
          <li><a href="https://twitter.com/#/ABQRESCUE">Twitter</a></li>
          
          <li><a href="http://www.facebook.com/abqrescue?ref=ts">Facebook</a></li>
          
          <li><a href="https://twitter.com/#/ABQRESCUE">Twitter</a></li>
          
          <li>Twitter</li>
          
    </ul> <!--header_feature_list-->

    Thanks for your help. BTW. I am having all sorts of conditional issues with 2.4. This is just the one that is on every page of this site.

     

  • #5 / Apr 11, 2012 11:39am

    Dan Decker

    7338 posts

    Hi tpayton,

    Let’s whittle this down to a simplified series of conditionals and test the result of that:

    {header_features}
        {if "{link}" != ""}
           <li><a href="http://{link}">{label}</a></li>
        {/if}
        {if "{page}" != ""}
           <li><a href="http://{page}">{label}</a></li>
        {/if}
        {if "{link}" == "" && "{page}" == ""}
           <li>{label}</li>
        {/if}
    {/header_features}

    Are you using the most current release of Matrix?

    Cheers,

  • #6 / Apr 11, 2012 2:51pm

    tpayton

    172 posts

    Dan,

    Same results with that code. Yes using 2.2.4 of matrix.

    BTW. I double checked and the formatting for both the link and the label are set to “none”.

  • #7 / Apr 12, 2012 1:18pm

    Dan Decker

    7338 posts

    Hey tpayton,

    Hrm… alright then - from your screenshot, you have Page as a drop down. In your template, you are checking for “not empty”, but the “empty” selection is “—- None—-”. By default, that *will be* the value and the Page drop down will never be empty.

    Back to your original code:

    {header_features}
           {if link}<li><a href="http://{link}">{label}</a></li>
              {if:elseif page != "--- None ---"} <li><a href="http://{page}">{label}</a></li>
              {if:else}<li>{label}</li>
          {/if}
       {/header_features}

    Any better?

    Cheers,

  • #8 / Apr 12, 2012 2:06pm

    tpayton

    172 posts

    Dan,

    I don’t believe that is the trouble, the page value when sent to “none” is indeed blank. I did a test here:

    {header_features}
           {if link}<li><a href="http://{link}">{label}</a></li>
              {if:elseif page != "--- None ---"} <li><a href="http://{page}">{label}</a></li>
              {if:else}<li>{label}</li>
          {/if}
    
    <li>Page=: {page}</li>
       {/header_features}

    And here was the results:

    <div id="header_features">
         <ul id="header_feature_list">
          
            <li><a href="http://">505-346-4673</a></li>
              
    <li>Page=: </li>
       
           <li><a href="https://twitter.com/#/ABQRESCUE">Twitter</a></li>
              
    <li>Page=: </li>
       
           <li><a href="http://www.facebook.com/abqrescue?ref=ts">Facebook</a></li>
              
    <li>Page=: </li>
       
           <li><a href="https://twitter.com/#/ABQRESCUE">Twitter</a></li>
              
    <li>Page=: </li>
       
            <li><a href="http://">Twitter</a></li>
              
    <li>Page=: </li>
       
        
         </ul> <!--header_feature_list-->
        </div> <!--header_features-->

    This exact same code works on a 2.3.1 site with Matrix 2.2.3.1 (we have a bunch of standard code we use) . Just to test, I reverted Matrix to this site to the version that worked with EE 2.31.  Same results.  Doh!

  • #9 / Apr 12, 2012 2:08pm

    tpayton

    172 posts

    Here is my original code that works in EE 2.3.1:

    {header_features}
           {if link}<li><a href="http://{link}">{label}</a></li>
              {if:elseif page} <li><a href="http://{page}">{label}</a></li>
              {if:else}<li>{label}</li>
          {/if}
       {/header_features}
  • #10 / Apr 17, 2012 12:28pm

    Dan Decker

    7338 posts

    Hi tpayton,

    There isn’t any reason that I can see why this isn’t working. No bugs in the tracker that tackle this, and you are certainly not the only one with code like this!

    I would like to see the whole template here, rather than just the non-working bit. There may be a clue in the bigger picture.

    Have you turned on template debugging to see what ExpressionEngine thinks it should be doing?

    Cheers,

  • #11 / Apr 17, 2012 12:59pm

    tpayton

    172 posts

    Hi Dan,

    I realized that I am having other conditional trouble with this site, even without being in a matrix.

    Just tried to send you a PM. Apparently your box is full. Can you shoot me an email my username on the board at onecreative.net. I’ll send you some login credentials for the site.

  • #12 / Apr 18, 2012 2:12pm

    tpayton

    172 posts

    Any word on this? My development is at a bit of stand still as I await a resolution.

    Thanks,

    - T.

  • #13 / Apr 19, 2012 3:00pm

    Shane Eckert

    7174 posts

    Hello tpayton,

    Most of us disable PM’s.

    Can you paste your template code here and mask any info you want hidden?

    Cheers,

  • #14 / Apr 19, 2012 3:10pm

    tpayton

    172 posts

    Sure here is my header. Just viewing this will showcase the problem:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    {exp:seo_lite use_last_segment='yes'
            title_postfix='{embed:title_postfix}'
            default_title='{embed:default_title}'
            default_keywords='{embed:default_keywords}'
            default_description='{embed:default_description}'
            title_override='{embed:title_override}'
            use_last_segment="yes"
    }
    
    <link rel="stylesheet" type="text/css" href="/arm2.0/main.css" />
    
    
    [removed][removed]
    
    <!--FontsKits-->
    <link rel="stylesheet" type="text/css" href="/fonts/ChunkFive-fontfacekit/stylesheet.css" />
    <link rel="stylesheet" type="text/css" href="/fonts/League-Gothic-fontfacekit/stylesheet.css" />
    <link href='http://fonts.googleapis.com/css?family=Michroma' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Abel' rel='stylesheet' type='text/css'>
    
    <!--nivo-slider-->
    
    <link rel="stylesheet" href="/scripts/nivoslider/nivo-slider.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="/scripts/nivoslider/themes/pascal/pascal.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="/scripts/nivoslider/themes/orman/orman.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="/scripts/nivoslider/themes/default/default.css" type="text/css" media="screen" />
    
    
    
    <!-- Smooth Div Scroll 1.1 - minified for faster loading-->
     <link rel="Stylesheet" type="text/css" href="/scripts/SmoothDivScroll/css/smoothDivScroll.css" />
     [removed][removed]
     [removed][removed]
     
    <!-- Smooth Scroll for jquery -->
     
     [removed][removed]
    
     [removed]
      $(window).load(function() {
       $("div#makeMeScrollable").smoothDivScroll({ 
        autoScroll: "onstart" , 
        autoScrollDirection: "endlessloopleft", 
        autoScrollStep: 1, 
        autoScrollInterval: 15, 
        startAtElementId: "startAtMe", 
        visibleHotSpots: "always"
       });
      });
     [removed]
     
     <!-- END Smooth Div Scroll 1.1 - minified for faster loading-->
     
    
    </head>
    
    <body>
    {login_bar_snippet}
    <a href="/beta/%22name=%22top%22&gt&lt/a&gt">/phpThumb/phpThumb.php?src={header_logo}&h=120&&zc;=1&q=90&f=png</a>
        </div>
        
        <div id="header_features">
         <ul id="header_feature_list">
          {header_features}
           {if link}<li><a href="http://{link}">{label}</a></li>
              {if:elseif page != "--- None ---"} <li><a href="http://{page}">{label}</a></li>
              {if:else}<li>{label}</li>
          {/if}
    
    <li>Page=: {page}</li>
       {/header_features}
        
         </ul> <!--header_feature_list-->
        </div> <!--header_features-->
       
        
        <div id="main_nav">
        
         {exp:structure:nav mode="full"}
      
        </div> <!--main_nav-->
        
         
        </div> <!--header-->
       </div>  <!--header_wrapper_inner-->
      
       </div> <!--header_wrapper-->
       
       <!-- End Header -->
    
      {/exp:channel:entries}
    <!-- Begin Content -->
    <div id="content">

     

     

  • #15 / Apr 20, 2012 5:18pm

    Dan Decker

    7338 posts

    Hi tpayton,

    Be on the lookout for an email from us. Be sure to include examples of where you are seeing the larger conditional problem.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases