Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a list of tags I'd like to remove the last comma. So is there something that works like the Ee backspace parameter?

share|improve this question
up vote 5 down vote accepted

An alternative, if you are getting the tags from the Tag Field type, is the Join filter:

{% if post.tags | length %}
    Tags: {{ post.tags | join(', ') }}
{% endif %}
share|improve this answer
Very clever and simple, ideal for tags :-) – noregt Dec 18 '14 at 16:41

There's a couple of special variables available while for looping through an array. In your case I'd make use of loop.last.

{{ tag }}{{ not loop.last ? ', ' }}

This is the expression using the ternary operator to keep the syntax short.

share|improve this answer
That did it, thanks! – noregt Aug 15 '14 at 9:46
@noregt no love for the CSS solution? – carlcs Aug 15 '14 at 9:46
Not really, if it's a list I'd also rather not have the separator in the html. (comma, backslash or similar) – noregt Aug 15 '14 at 9:49
That's the exact reason to use CSS over HTML, @noregt! You'd only apply the class to those inline lists you wanna STYLE like this. – carlcs Aug 15 '14 at 9:51
I meant the LAST parsed separator, but I get your point if you're working with official lists. I was working with a simple paragraph line and comma's. But I admit that's not very good html. – noregt Aug 15 '14 at 9:58

If you you have a given string and can't influence how it is generated, use the slice filter to crop that last comma:

{% set tags = 'Alpirsbacher Klosterbräu, Rothaus Tannenzäpfle, Neumarkter Lammsbräu, ' %}

{# Remove the last two chars ", " from the string #}
{{ tags|slice(0, -2) }}
share|improve this answer
Aha that's even better, so slice is the EE backspace alternative :-) – noregt Aug 15 '14 at 13:34
No, it's the worst way to do it in my opinion, @noregt! – carlcs Aug 15 '14 at 13:35
Haha I understand your annoyance, but essentially I wanted to know the alternative for the EE backspace parameter. You changed the title, but that was what I meant to ask. – noregt Aug 16 '14 at 8:33
Yep, I think the new title fits this Q/A better. You asked for a way to make your tag list and that EE thing was just a side note for me (yes, there are people using Craft NOT coming from EE :D). Cheers, @noregt. – carlcs Aug 16 '14 at 8:49
Oh, and it's your question. Don't feel being pushed to accept the CSS solution! (but do it!!!) – carlcs Aug 16 '14 at 8:51

What about using CSS for that?

.u-inlineList {
  display: inline;

.u-inlineList-item {
  display: inline;
  list-style: none;

.u-inlineList-item:after {
  content: ", ";

.u-inlineList-item:last-child:after {
  content: "";
share|improve this answer
That is an option, but I would prefer if that can be done through craft. Or can't it? – noregt Aug 15 '14 at 9:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.