Answers.Body: <p>The <a href="http://twig.sensiolabs.org/doc/templates.html#whitespace-control">spaceless</a> tag only removes whitespace between HTML tags. You have to use the <a href="http://twig.sensiolabs.org/doc/templates.html#whitespace-control">whitespace control modifier</a> on your tags to remove leading and or trailing whitespace.</p>
  
  <p>Additionally I'd use the <a href="http://twig.sensiolabs.org/doc/templates.html#other-operators">ternary operator</a> for your conditionals (and put the hyphen inside it):</p>
  
  <pre><code>{% for date in entry.d_date %}
      {{  date.showMonth == 1 ? date.date.month ~ '-' : '' -}}
      {{- date.showDate == 1 ? date.date.day ~ '-' : '' -}}
      {{- date.date.year }}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-23T13:49:24.427Z
Answers.LastActivityDate: 2014-06-23T13:59:04.300Z
Answers.LastEditDate: 2014-06-23T13:59:04.300Z
Answers.UserDisplayName: carlcs
Body: <p>I have the following code.</p>
  
  <pre><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 %}
  </code></pre>
  
  <p>Which outputs 1- 1- 2014</p>
  
  <p>Is there anyway to get rid of the whitespace without touching the indentation? I've used <code>{spaceless}</code> but it's not working.</p>
  
Tags: <templating><datetime><whitespace>
Title: How do I get rid of whitespace when rendering without touching template indentations?
ThreadText: # How do I get rid of whitespace when rendering without touching template indentations?
  
  (Asked by: username_0 on 2014-06-23)
  
  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.
  
  **Tags:** templating, datetime, whitespace
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-23. Score: 13 | Accepted answer
  
  The [spaceless](http://twig.sensiolabs.org/doc/templates.html#whitespace-control) tag only removes whitespace between HTML tags. You have to use the [whitespace control modifier](http://twig.sensiolabs.org/doc/templates.html#whitespace-control) on your tags to remove leading and or trailing whitespace.
  
  Additionally I'd use the [ternary operator](http://twig.sensiolabs.org/doc/templates.html#other-operators) 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 %}
  
  ```
  
  
  ---
  
  