How to build a sentence based on tags I try to build a complete sentence based on tags as follows:

This is a sentence with tag1, tag2 and tag3.

My code is:

{% set topics = entry.topics.first %}

{% for topic in entry.topics.offset(1) %}
    {% if topic != entry.topics.last %}
       {% set topics = topics ~ ', ' ~ topic %}
    {% endif %}
{% endfor %}

&lt;p&gt;This is a sentence with {{ topics }} and {{ entry.topics.last }}.&lt;/p&gt;


My problem is that the if clause does not work. The results is always:

This is a sentence with tag1, tag2, tag3 and tag3.
I think it'll be easier and more efficient to achieve that if you use the loop functionality instead of querying the actual tags. I think this code does what you want:

{% set topics = '' %}

{% for topic in entry.topics %}
    {% set topics = topics ~ topic ~ (loop.index &lt; loop.length-1 ? ', ' : loop.index &lt; loop.length ? ' and ') %}
{% endfor %}

&lt;p&gt;This is a sentence with {{ topics }}.&lt;/p&gt;