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

Good indentation ? #29

Closed
leopoiroux opened this issue Dec 11, 2013 · 5 comments
Closed

Good indentation ? #29

leopoiroux opened this issue Dec 11, 2013 · 5 comments

Comments

@leopoiroux
Copy link

I do not know how to change syntax. Can you ensure that the indentation is respected automatically ?

Example :

{% if condition %}
     {% for key, val in array %}
          {{ val }}
     {% endfor %}
{% else %}
     {{ my_other_value }}
{% endif %}
@uhnomoli
Copy link
Owner

uhnomoli commented Feb 2, 2014

I'm not sure exactly what you're asking here. Can you give me an example of the observed and expected behavior?

@leopoiroux
Copy link
Author

Hi,
If you paste this code in SublimeText and you go on "Edit >> Line >> Reindent". The indentation is not respected. See the result :

{% if condition %}
{% for key, val in array %}
{{ val }}
{% endfor %}
{% else %}
{{ my_other_value }}
{% endif %}

@pimpreneil
Copy link

I have the same problem:
The automatic indentation (command Indentation:Reindent Lines) of my twig blocks between each other is not working.
Indeed, the twig coding standards stipulates that you should "Indent your code inside tags (use the same indentation as the one used for the target language of the rendered template)" c.f.: http://twig.sensiolabs.org/doc/coding_standards.html.

Using your bundle, I get that:

{% if condition %}
{% for key, val in array %}
{{ val }}
{% endfor %}
{% else %}
{{ my_other_value }}
{% endif %}
{% for item in seq %}

Instead of that:

{% if condition %}
    {% for key, val in array %}
        {{ val }}
    {% endfor %}
{% else %}
    {{ my_other_value }}
{% endif %}

@pimpreneil
Copy link

I have started writing a tmPreference file to handle a proper indentation for twig. Here it is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Indent</string>
    <key>scope</key>
    <string>text.html.twig</string>
    <key>settings</key>
    <dict>
        <key>decreaseIndentPattern</key>
        <string>(?x)
        ^\s*
        (?:
        (?:\{%[ ]end[^}]+[ ]%\})|
        (?:\{%[ ]else[ ]%\})|
        (?:\{%[ ]elseif[ ]+[^%])|
        (?:&lt;/(?!html)
          [A-Za-z0-9]+\b[^&gt;]*&gt;
        |--&gt;
        |&lt;\?(php)?\s+(else(if)?|end(if|for(each)?|while))
        |\}
        ))</string>
        <key>increaseIndentPattern</key>
        <string>(?x)
        ^\s*
        (?:
        (?:\{%[ ](?!import|extends|end|include|form_theme|set|do)(?:[^ ]*)[ ][^%]*%\})
        |(?:\{%[ ]set[ ]%\})
        |(?:&lt;(?!\?|area|base|br|col|frame|hr|html|img|input|link|meta|param|[^&gt;]*/&gt;)
          ([A-Za-z0-9]+)(?=\s|&gt;)\b[^&gt;]*&gt;(?!.*&lt;/\1&gt;)
        |&lt;!--(?!.*--&gt;)
        |&lt;\?php.+?\b(if|else(?:if)?|for(?:each)?|while)\b.*:(?!.*end\1)
        |\{[^}"']*))$
        </string>
        <key>bracketIndentNextLinePattern</key>
        <string>&lt;!DOCTYPE(?!.*&gt;)</string>
    </dict>
    <key>uuid</key>
    <string>E3351EDC-430A-42E7-9926-6E4C7F34E84F</string>
</dict>
</plist>

@uhnomoli
Copy link
Owner

I've added an indentation preferences file. Feel free to reopen this issue if experience any issues with it.

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

3 participants