CMS Development

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Help with Hubl loop

SOLVE

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

0 Upvotes
2 Accepted solutions
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Help with Hubl loop

SOLVE

@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 %}
Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Help with Hubl loop

SOLVE

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

Anton Bujanowski Signature

View solution in original post

0 Upvotes
3 Replies 3
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Help with Hubl loop

SOLVE

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

Anton Bujanowski Signature
0 Upvotes
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Help with Hubl loop

SOLVE

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

 

Terry

0 Upvotes
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Help with Hubl loop

SOLVE

@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 %}
Stefen Phelps, Community Champion, Kelp Web Developer