1

I have a FOR loop that should be displaying all the entry titles on one line. But instead, it is outputting them on separate lines.

I want to see:

Developer: Jane Doe, Jim Doe

Instead, I am getting:

Developer: Jane Doe
Developer: Jim Doe

My code:

{% set developers = entry.GamesDeveloper %}

{% for developer in developers %}
    <li>Developer: <a href="{{ developer.url }}">{{ developer.title }}</a></li>
{% endfor %}
4

This is because you're using an html list <li> element, which by default puts each element on a new line. You could style away the newline I suppose, but why use it at all...there are a bunch of ways of doing this, but this is one simple one:

{% set developers = entry.GamesDeveloper %}
{% if developers|length %}
Developer: 
{% for developer in developers %}           
    <a href="{{ developer.url }}">{{ developer.title }}</a>{% if not loop.last %}, {% endif %}
{% endfor %}
{% endif %}
  • I need to be able to keep it within a html list though. I have data before and after that will also b in a list. aka – DevServe Dec 21 '16 at 0:32
  • Ok well then you need to style the list I guess - something like li { display: inline; } in your css should do it. – Jeremy Daalder Dec 21 '16 at 0:34
  • ...but you'll still need to put Developer: outside your for loop of course. And if you want the commas check the not loop.last condition.... – Jeremy Daalder Dec 21 '16 at 0:35

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.