Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Avoiding Volt to add spaces when inserting functions and variables

When I have a code, event a simple one, that prints the content of a variable to the template and/or performs a function or verifies a condition, I usually tab the HTML in the volt template to obain more readability.

These tabs are translated in the final HTML output as spaces, which translates in the browser to see undesired spacings.

Example:

       <h1>
         {% if the_title is defined %}
             {{ the_title }}
         {% endif %}
     </h1>

Translates to:

       <h1>                                      Title                               </h1>

and I see a space before and a space after the "Title".

How can I avoid this?

Thank you.

Just change in your editor tabs to be TABS, not spaces.



3.4k

Just change in your editor tabs to be TABS, not spaces.

they're actually tabs, not spaces at all.

Are you sure ? I have tabs too and i dont have any spaces.



44.8k
Accepted
answer

Change it to:

           <h1>
             {%- if the_title is defined -%}
                 {{ the_title }}
             {%- endif -%}
         </h1>