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.

Why would this ELSE statement post twice?

July 29, 2011 10:15am

Subscribe [3]
  • #1 / Jul 29, 2011 10:15am

    Pauly

    16 posts

    When accessing the category or single entry the <h1> only prints once as expected, however when accessing my templategroup/template directly the ELSE statement is printing <h1>Stuff</h1> twice. I’m pretty sure I must be doing something wrong but I can’t figure it out. Any clues what I might be doing wrong for this to happen?

    {exp:channel:entries channel="articles"}
    
         {if category_request}
    
         <h1>Category</h1>
                
         {if:elseif "{total_results}"=="1"}
                
         <h1>Single Entry</h1>
                
         {if:else}
                
         <h1>Stuff</h1>
                
         {/if}
    {/exp:channel:entries}

    Edit: Sorry, my version build info; v2.2.1 - Build: date 20110705

  • #2 / Jul 30, 2011 11:05am

    Pauly

    16 posts

    Any thoughts on this?

  • #3 / Jul 30, 2011 12:13pm

    LMO

    203 posts

    Does your channel have multiple entries? You can add limit=“1” to only have it loop once.

  • #4 / Jul 30, 2011 1:54pm

    Pauly

    16 posts

    Hey VIM thanks for the response. Yes, there would be multiple entries once I replace <h1>stuff</h1> with the desired content. I’m also trying to understand why this would print twice so I can avoid it in the future (unless it’s a bug with EE?).

    If it’s not a bug, would I have to reform my statements and use {exp:channel:entries channel="articles"} twice to get my desired effect?

  • #5 / Jul 30, 2011 2:01pm

    LMO

    203 posts

    If your looking to only have stuff print once of the header of the page with multiple entries below it you can also wrap like so

    {if count == '1'}
      <h1>stuff</h1>
    {/if}
  • #6 / Jul 30, 2011 2:07pm

    Dan Decker

    7338 posts

    Hi Pauly,

    VIM, thanks for the assist!

    I’m going to move this over into Community Help to keep the discussion going.

    Pauly, feel free to start a new thread if you experience any technical issues with ExpressionEngine.

    Best,

  • #7 / Jul 30, 2011 3:09pm

    Pauly

    16 posts

    Okay, this might work. Thank you VIM. I need to adapt it slightly for what I’m trying to do since this isn’t within my header and I have some more conditions to run, but I can see it working, thanks.

    Just for future reference, even if my template is not my header, content will still print twice if I use the {if:else}, and I should always clarify the condition, correct? If not, do you have any insight as to why this would print twice? I’m still not quite understanding that.

  • #8 / Jul 30, 2011 5:27pm

    LMO

    203 posts

    Sorry what I meant was the H1 tag when I said header.

    Without seeing the full code and knowing what each custom fields/tags are, its hard to pin point whats going on and figure out why its behaving unexpectedly. I can only assume that you have two entries in the channel and its printing that code block twice since the else will catch everything that didnt match the conditions.

  • #9 / Jul 30, 2011 9:43pm

    Pauly

    16 posts

    Edit: VIM, I managed to do what I was trying to achieve using an IF statement for segment_2 to check for my indicator, the category_request was what was holding me back from achieving my desired affect of using articles/index to drive three scenarios. Thank you very much for your help.

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

ExpressionEngine News!

#eecms, #events, #releases