<p>Loop through the categories of the entry, add and if it's not the last loop index, like so:</p>

<pre><code>{% for category in  entry.categoryFieldHandle %}
 {{category.title}} {{ loop.last ? '': 'and '}}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-02-07T17:53:38.347Z
2017-02-07T17:53:38.347Z
Jan_dh
<p>The accepted answer will work, certainly, but thanks to the way Craft works behind the scenes there is a more compact and elegant solution:</p>

<pre><code>{{ entry.categoryFieldHandle|join(' and ') }}
</code></pre>

<h2>Why this works</h2>

<p>The Entry's category field (accessed via <code>entry.categoryFieldHandle</code>) returns an <a href="https://craftcms.com/classreference/models/ElementCriteriaModel" rel="nofollow noreferrer">ElementCriteriaModel</a>, which implements <a href="http://php.net/manual/en/class.arrayaccess.php" rel="nofollow noreferrer">PHP's ArrayAccess interface</a>.</p>

<p>In plain English, this means that we can treat the ElementCriteriaModel as an array.</p>

<p>The ElementCriteriaModel returns a collection of <a href="https://craftcms.com/classreference/models/CategoryModel" rel="nofollow noreferrer">CategoryModel</a> objects, each of which implements <a href="http://php.net/manual/en/language.oop5.magic.php#object.tostring" rel="nofollow noreferrer">a <code>__toString</code> method</a> (returning the Category title). This effectively means we can treat the object as a string.</p>

<p>The above features mean that we can pass our ElementCriteriaModel directly to <a href="http://twig.sensiolabs.org/doc/1.x/filters/join.html" rel="nofollow noreferrer">the Twig <code>join</code> filter</a>, and it will concatenate the Category titles using the "glue" string " and ".</p>

CC BY-SA 3.0
2017-02-08T17:22:01.180Z
2017-02-08T17:22:01.180Z
Stephen Lewis
<p>I have some entries that have more than one category assigned to them (under the same category group).  For example, Entry X might be assigned to Category A and Category D.   How do I get it to print <code>"Category A **and** Category B"</code> instead of <code>Category A Category B"</code>?</p>

<templating>
How can I add "and" between multiple categories assigned to an entry?
# How can I add "and" between multiple categories assigned to an entry?

(Asked by: username_0 on 2017-02-07)

I have some entries that have more than one category assigned to them (under the same category group). For example, Entry X might be assigned to Category A and Category D. How do I get it to print `"Category A **and** Category B"` instead of `Category A Category B"`?

**Tags:** templating

---

## 2 answers

### Answer by username_1 on 2017-02-07. Score: 3 | Accepted answer

Loop through the categories of the entry, add and if it's not the last loop index, like so:
{% for category in  entry.categoryFieldHandle %}
 {{category.title}} {{ loop.last ? '': 'and '}}
{% endfor %}


---

### Answer by username_2 on 2017-02-08. Score: 2

The accepted answer will work, certainly, but thanks to the way Craft works behind the scenes there is a more compact and elegant solution:
{{ entry.categoryFieldHandle|join(' and ') }}

Why this works
The Entry's category field (accessed via entry.categoryFieldHandle) returns an ElementCriteriaModel, which implements PHP's ArrayAccess interface.
In plain English, this means that we can treat the ElementCriteriaModel as an array.
The ElementCriteriaModel returns a collection of CategoryModel objects, each of which implements a __toString method (returning the Category title). This effectively means we can treat the object as a string.
The above features mean that we can pass our ElementCriteriaModel directly to the Twig join filter, and it will concatenate the Category titles using the "glue" string " and ".


---

