1

I'm running into a bizarre issue with EE that I've never noticed before (using v2.10.1). I'm using a "justified" grid where you set your column container to text-align: justify, give them the right width and they float themselves without having to deal with margins and all that mess.

Works great in my static code until I start using channel:entries loops.

Here's how it should look:

<div class="col-wrapper col2">
  <div class="col"></div>
  <div class="col"></div>
</div>

However, whenever I put the columns in a channel loop and use some sort of conditional statement, EE is stripping the whitespace and the end of each column so that they all end up on the same line which totally jacks up the spacing/floating that the justified grid does.

<div class="col-wrapper col2">
  {exp:channel:entries channel="channel"} 
   {if any_conditional}{/if}
     <div class="col"></div>
   {/exp:channel:entries}
</div>

Gives me:

<div class="col-wrapper col2">
  <div class="col"></div><div class="col"></div>
</div>

I've tried adding an &nbsp; after the last dive inside the channel loop, and that helps, but it adds extra space and makes the grid end up being off enough that it's really frustrating.

What's going on here? Is there a way to make EE stop stripping this linebreak/whitespace out?

Help!

5
  • Have you tried adding a line break tag in your loop and use the backspace parameter to remove it from the last iteration? – jrothafer Dec 21 '15 at 16:44
  • Yeah I tried that as well. But adding the break tag makes all my columns stop stacking next to each other! – FortySeven Media Dec 21 '15 at 17:10
  • 1
    I think I ran in to this issue in a weird way somewhere else (it had to do with an RSS feed). My solution was to add a new line to the end of the loop, and dump a blank echo, IE <?php echo ""; ?>. Try that (turning on PHP parsing of course). – jrothafer Dec 21 '15 at 17:19
  • 1
    This got me on the right track. It definitely worked, but I wasn't too keen on enabling PHP for every page that had a grid on it. Turns out Low Replace can do the same thing: {exp:low_replace find="SPACE" replace="NEWLINE"} {/exp:low_replace} – FortySeven Media Dec 22 '15 at 12:58
  • I'm having this issue as well - I didn't really need the conditionals so I was able to just remove them. Would not have occurred to me to try that. – Christy Collins Jun 24 '16 at 4:24
1

Somewhere around 2.9 / 2.10 a new template lexer/parser was introduced.
The new conditional parser does indeed do a trim($out).

method: closeBuffer() in:
expressionengine/library/parser/conditional/parser.php

Although it is not recommended to change EE core,
you can change it to return ltrim($out); or return $out;
to keep some of your whitespace around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.