Help with Hubl loop

I am trying to figure out how to add a separator to the items displayed from the loop except for the last item.

Loop-

{% for t in p.topic_list %}
<a href=“{{ group.absolute_url }}/topic/{{ t.slug }}” rel=“nofollow”>{{ t }} </a>
{% endfor %}

Example: item - item - item - item

Thanks,

Terry McMillan

@tmcmillan99 you could do this:

{% for t in p.topic_list %}
<a href="{{ group.absolute_url }}/topic/{{ t.slug }}" rel="nofollow">{{ t }}</a>{% unless loop.last %} - {% endunless %}
{% endfor %}

Hi @tmcmillan99,

it’s possible with an additional if loop and the loop.last property.

Change your code as following:

{% for t in p.topic_list %}
<a href="{{ group.absolute_url }}/topic/{{ t.slug }}" rel="nofollow">{{ t }} </a>
<span class="seperator">-</span>
{%if loop.last %}<a href="{{ group.absolute_url }}/topic/{{ t.slug }}" rel="nofollow">{{ t }} </a>{% endif %}
{% endfor %}

I’ve added the seperator just to display where it belongs.

best,

Anton

Awesome! Thank you both for the solutions. I’m sure either one will work great.

Terry