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
"Html" Lexer #3867
Comments
To clarify, there are 2 possible levels to this proposal
|
yes please, the current syntax of twig is sometimes unreadable, for example consider this statement here, it isn't really clear when an attribute starts and when it ends, with html syntax it will be {% if form.choices is defined %}
{{ form_row(form.choices, {'attr': {':disabled': 'fieldType != "select"'}, 'row_attr': {'x-show': 'fieldType == "select"'} }) }}
{% endif %} |
@kbond so you propose to add the tag |
I think Ryan's second proposal (2) is probably the best starting point. I believe this would simplify twig components code and, assuming we get support/adoption, perhaps sell the idea of html syntax in core (Ryan's first proposal). |
What would the first proposal ("html syntax in core") mean outside of the Symfony framework? How would such syntax translate when used this way: index.php<?php
require './vendor/autoload.php';
$loader = new \Twig\Loader\ArrayLoader([
'index.twig' => '<twig:if foo == true>Here<twig:else>There<twig:endif>'
]);
$env = new \Twig\Environment($loader, []);
$env->display('index.twig', []); php index.php |
IIRC, the way we have html-syntax working in twig components is: translate the html syntax to standard twig syntax, then compile down to php as normal. I'm quite out of my depth here but I believe html-syntax in core could remove the "translate the html syntax to standard twig syntax" step. So essentially, your example would just work (assuming this new lexer is enabled by default). |
With the popularity of Twig Component HTML Syntax I wanted to discuss the possibility of adding an official html lexer in Twig core. What we're doing in twig components is sort of a hack: converting
<twig:...
to{% ...
. An official lexer would remove this conversion process.We've already added the block tag (
<twig:block name="title">
) in twig components. We can envision users asking for more official Twig tags as html tags.I know this would not be an easy or quick task and there would be a lot to consider for each tag:
Alternatively, if it's decided to not include in core, what about opening the lexer up for extension?
The text was updated successfully, but these errors were encountered: