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:elseif causing line feeds to disappear

November 17, 2010 4:33pm

Subscribe [3]
  • #1 / Nov 17, 2010 4:33pm

    hd 

    156 posts

    I’m having an issue with v2.1.1 build 20101020.

    elseif statements seem to eat line feeds from the HTML output, which makes my markup look very untidy unnecessarily.

    if:elseif Example:

    line one
    line two{if segment_1=="visitors"}
        tabbed line{/if}
        another tabbed line
    last line

    ...will display (at /visitors):

    line one
    line two
        tabbed line
        another tabbed line
    last line

    ... as expected, right? However when I include an elseif:

    line one
    line two{if segment_1=="visitors"}
        tabbed line{if:elseif segment_1=="anything"}{/if}
        another tabbed line
    last line

    ... will output:

    line one
    line two    tabbed line    another tabbed line
    last line

    ... which makes no sense to me. Bug? Or am I just doing something wrong?

  • #2 / Nov 18, 2010 9:06am

    Sue Crocker

    26054 posts

    hd,

    I tried something similar on my end.. but using the last_segment variable.

    <h3>If Else If Test</h3>
    
    <p>{if last_segment == "ifelse"}<br />
    IFELSE!<br />
    {if:else}<br />
    {last_segment}<br />
    {/if}

    How does what I did differ?

  • #3 / Nov 18, 2010 11:35am

    hd 

    156 posts

    Perhaps I am not being clear.

    Here is a better example:

    {if last_segment == "test"}line one{/if}
    line two

    will output in the html:

    line one
    line two

    However, when using if:else or if:elseif the behavior is different:

    {if last_segment == "test"}line one{if:else}alternate line one{/if}
    line two

    will output in the html:

    line oneline two

    Notice the line feed immediately following the IF statement was eliminated. This appears to be a bug, as it does not occur with singular-conditional IF statements. If another character is placed after the closing {/if} (but before the line feed) such as a space, the issue does not occur.

  • #4 / Nov 19, 2010 1:36am

    John Henry Donovan

    12339 posts

    hd,

    I really don’t think would be considered a bug but more of a feature request. It works like this even in EE1.x. Your feature request will get read by a dev.

    If you write you drop the closing {/if} to the next line for any advanced conditionals you will have no problem with your source so

    {if last_segment == "test"}line one{if:else}alternate line one
    {/if}
    line two
    line one
    line two{if segment_1=="visitors"}
        tabbed line{if:elseif segment_1=="anything"}
    {/if}
        another tabbed line
    last line
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases