6

I have the following code.

{% spaceless %}
{% for date in entry.d_date %}
    {% if date.showMonth == 1 %}
    {{ date.date.month }}-
    {% endif %}
    {% if date.showDate == 1 %}
    {{ date.date.day }}-
    {% endif %}
    {{ date.date.year }}
{% endfor %}
{% endspaceless %}

Which outputs 1- 1- 2014

Is there anyway to get rid of the whitespace without touching the indentation? I've used {spaceless} but it's not working.

13

The spaceless tag only removes whitespace between HTML tags. You have to use the whitespace control modifier on your tags to remove leading and or trailing whitespace.

Additionally I'd use the ternary operator for your conditionals (and put the hyphen inside it):

{% for date in entry.d_date %}
    {{  date.showMonth == 1 ? date.date.month ~ '-' : '' -}}
    {{- date.showDate == 1 ? date.date.day ~ '-' : '' -}}
    {{- date.date.year }}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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