-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
add component to guard tag #4390
Comments
given that Twig itself knows nothing about twig components (which are a concept of symfony/ux, not of Twig), I don't think it can be added in the core tag. However, from a quick look at the implementation of TwigComponent in symfony/ux, I don't have the impression that they validate component names are compile time. If this is indeed a runtime check, a |
Yeah, that's why I opened it there. But the original PR mentioned something like "currently the guard tags supports filters and functions", it made me think perhaps where was a way a 3rd-party component could "attach" itself to it. But a component_exists() function seems like an easier solution anyway. |
there is not hook for third-party extensions in it (which would not be possible anyway, as the implementation relies on checking for that filter/function/test on the Environment instance). |
thanks for the explanation! |
A {% guard function component %}
<twig:bootstrap:accordion />
{% endguard %}
|
@smnandre yes, but it'd also be nice to check if a specific component was installed. {% set count = 15 %}
{% guard function component %}
{% if (component_exists('bootstrap:badge') %}
<twig:bootstrap:badge :message="count" />
{% else %}
{# badge is in my bundle if ux-component is installed, so I don't need to check for it #}
<twig:my-bundle:badge :message="count" />
{% endif %}
{% else %}
<span class="badge">{{ count }}</span>
{% endguard %} |
I know I Even answered you about this on the UX repository :) |
I love the guard tag, and was wondering if it could be applied to twig components, too, so that something like this would work:
I put the issue in the ux repo, but perhaps it belongs here.
symfony/ux#2255
The text was updated successfully, but these errors were encountered: