-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Parser doesn't allow <body {% block body_attributes %}{% endblock %}> #61
Comments
It looks like this dates back to trivago#60 |
I'm not sure how to tackle this issue. Adding support for twig tag inside html element might not be complicated. Example <div {% block class %}class="hidden"{% endblock class %}>
</div> On the other hand, if we need to imlement support for twig tag inside attribute value, example <div class="{% block class %}hidden{% endblock class %}">
</div> the parser logic will be significantly more complex. Ideally, all twig features should be supported. However we lack the skill to actually implement this features. Should we partially implement this feature, allow twig tag inside html element? Skipping twig tag inside html attribute value. Or don't bother to add this feature if not fully implemented? Waiting for feedback. |
I think there are way more elegant solutions this, like using an extension like: https://github.com/parisek/twig-attribute. And then just setting the variable that sets all the attributes via the child template. |
TBH, I'm not a big fan of using twig tag inside html element. There's other solution that I think more elegant, such as using extension like example above or using something like twig-component. In my experience, the usage of block expression on html attribute can be achived using ternary expression (which this plugin supported) in some cases. And so far I can live without this feature. Unless there's strong opinion that this should be implemented, I don't want to add this feature. Feel free to send pull request. Maybe I can work from there. Thanks. |
I don't know what the non-existing specification (not even joking here) of Twig says about this. But in my advanced experience building with Twig, using Here are the (mostly better) alternatives for this, from my point of view:
Or as @zackad said, the Twig Components from Symfony's UX initiative. In case you are anyway in the Symfony ecosystem. (my 50 cents as a Twig user using the Prettier formatter) |
Just installed this in order to test it and this is the first thing I ran into. We use twig tags like this everywhere, so converting everything isn't a small task and probably not a goal of ours. I know liquid supports tags like this and they have a prettier plugin as well. |
A twig template with
in it passes the linter
symfony console lint:twig templates
, but prettier-plugin-twig's parser reports:usage for this when calling the body_attributes block allows for passing in class and data-controller as follows:
The text was updated successfully, but these errors were encountered: