1

seems like a silly question but I cannot seem to find an answer and I'm wondering if I'm not just phrasing it incorrectly or using the wrong terms...

I simply want to force a newline within a loop returning content:

  <ul>
  {exp:channel:entries channel="duh"}
    <li><a href="{site_url}{url_title}/">{title}</a></li>
  {/exp:channel:entries}
  </ul>

so that the output will change from:

  <ul>
    <li><a href="/link-1/">link-1</a></li><li><a href="/link-2/">link-2</a></li><li><a href="/link-3/">link-3</a></li>[etc]
  </ul>

to:

  <ul>
    <li><a href="/link-1/">link-1</a></li>
    <li><a href="/link-2/">link-2</a></li>
    <li><a href="/link-3/">link-3</a></li>
    [etc]
  </ul>

it must be something simple that I'm missing, but I cannot find any references to making it happen in the EE docs or various searches here and elsewhere.

I thought it might be something obvious like adding a {\n} or {NEWLINE} into the mix, but no luck as of yet finding something that works.

little help please?

1

TBH, your code output is a result of your code format.

Turn this:

<ul>
{exp:channel:entries channel="duh"}
    <li><a href="{site_url}{url_title}/">{title}</a></li>
{/exp:channel:entries}
</ul>

into this:

<ul>
{exp:channel:entries channel="duh"}
    <li>
        <a href="{site_url}{url_title}/">
            {title}
        </a>
    </li>
{/exp:channel:entries}
</ul>

And all your troubles will go away. In my experience, this style of HTML/Template formatting makes for, by far, the easiest debugging during development. It also makes development itself much easier to handle, and templates much easier to read amongst developers. Once you're in production, all of your HTML should be minified anyways, but even if it isn't, a thousand carriage returns in a template aren't going to hurt your load time noticeably.

Edit

Oooo, yeah, you can't do anything about that one, to my knowledge. There is a method, however, you will hate it with a passion. Turn PHP on output for any particular template aaaaand:

<ul>
{exp:channel:entries channel="duh"}
    <li>
        <a href="{site_url}{url_title}/">
            {title}
        </a>
    </li>
    <?php echo "\r\n"; ?>
{/exp:channel:entries}
</ul>

That'll do it. The problem is that the core entries module trims and removes new lines after each loop, essentially screwing you. On PHP set to output, however, this will result in a PHP stage after the template parsing stage, so you get this:

<ul>
    ...
    <li>
        <a href="www.site.com/url-title">
            This entry's title!
        </a>
    </li><?php echo "\r\n"; ?><li>
        <a href="www.site.com/url-title">
            This next entry's title!
        </a>
    </li>
    ...
</ul>

which then gets its PHP evaled, and the result is something like this:

<ul>
    ...
    <li>
        <a href="www.site.com/url-title">
            This entry's title!
        </a>
    </li>
<li>
        <a href="www.site.com/url-title">
            This next entry's title!
        </a>
    </li>
    ...
</ul>

You can't really win too much with that last line. Unless someone else knows a secret method (other than core hacking).

4
  • I did have extra returns in there during my trials, but I'll give this a shot again. in our workflow, completely minified isn't an option, but I'm also trying to make the source more readable for peers and client contacts. you should hear the complaints about minified scss files when they end up on the server as css ;)
    – Jeremy
    Sep 30 '15 at 21:50
  • tested, and that's closer, but the issue isn't within the markup, it's at the end of each line. with that in mind, I still end up with a </li><li> on the same line in the source. I can probably work with that, but not sure if they'll like the format. I find it odd that there's no way to prescribe a newline character, but then that's probably why I was unable to find it in the docs.
    – Jeremy
    Sep 30 '15 at 22:10
  • OH yeah, forgot about that. Updating my answer @Jeremy
    – jrothafer
    Oct 1 '15 at 0:25
  • actually, that's perfect. I have rudimentary php knowledge as I had built php interfaces for sites for a years, using basic conditionals, variables, includes, etc... nothing complex, but just the proper building of sites and pages. I don't mind adding a php tag or two here and there for these types of cases. we normally don't have php turned on simply because it hasn't been needed yet (yay, ee and dev/addon community). unless it becomes a major resource hog or has some other ill-natured affects, I think that's a perfect workaround!
    – Jeremy
    Oct 1 '15 at 16:11

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.