Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant whitespace around {% %} #99

Open
jkufner opened this issue Jan 24, 2017 · 0 comments
Open

Redundant whitespace around {% %} #99

jkufner opened this issue Jan 24, 2017 · 0 comments

Comments

@jkufner
Copy link

jkufner commented Jan 24, 2017

I'm using the Symfony bundle and Twig. There is a short example of the whitespace problem:

HAML template:

- extends 'AppBundle::layout_text.html.haml'

- block content
  #A Hello world!
  -# ...
  #B
    - if true
      - block some_indented_block
        #C Hello.
  #D Bye.

Generated Twig template:

{% extends 'AppBundle::layout_text.html.haml' %}
{% line 3 %}{% block content %}
  <div id="A">Hello world!</div>
  <div id="B">
{% line 7 %}    {% if true %}
      {% block some_indented_block %}
        <div id="C">Hello.</div>
      {% endblock %}
    {% endif %}
  </div>
  <div id="D">Bye.</div>
{% endblock %}

Final HTML (#page_content_text is from the parent template):

  <div id="A">Hello world!</div>
  <div id="B">
                  <div id="C">Hello.</div>
            </div>
  <div id="D">Bye.</div>

Take a look at {% %} tags in the Twig template. There is plenty of redundant whitespace which breaks indenting of the final HTML. For example the space between {% line 7 %}, {% if true %} and {% block some_indented_block %}`.

It would be much better if the {% %} tags were on their own lines and not indented at all:

{% extends 'AppBundle::layout_text.html.haml' %}
{% line 3 %}{% block content %}
  <div id="A">Hello world!</div>
  <div id="B">
{% line 7 %}{% if true %}{% block some_indented_block %}
        <div id="C">Hello.</div>
{% endblock %}
{% endif %}
  </div>
  <div id="D">Bye.</div>
{% endblock %}

Which will produce much better HTML:

  <div id="A">Hello world!</div>
  <div id="B">
        <div id="C">Hello.</div>
  </div>
  <div id="D">Bye.</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant