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

[TwigComponent] Test if component exists (guard?) #2255

Open
tacman opened this issue Oct 10, 2024 · 3 comments
Open

[TwigComponent] Test if component exists (guard?) #2255

tacman opened this issue Oct 10, 2024 · 3 comments

Comments

@tacman
Copy link
Contributor

tacman commented Oct 10, 2024

The new {% guard %} tag merged today is will very helpful for testing if a filter/function/test exists.

Is there a way to test if a component exists?

{% guard component badge %}
   <twig:badge color="red">Badge!</twig>
{% else %}
   <span class="badge">no component</span>
{% endguard %}
@tacman tacman added the RFC label Oct 10, 2024
@Kocal
Copy link
Member

Kocal commented Oct 10, 2024

Hi Tac,

for the moment there is no way to test if a Twig component exists.

@tacman
Copy link
Contributor Author

tacman commented Oct 10, 2024

I wonder if the ux component could "hook into" the guard tag.

Two situations:

  • the ux component isn't installed
  • ux component is installed by there's no component of a particular name.

The issue is mostly with bundles. I find myself using components in other bundles, which creates a dependency that should be optional.

Not exactly related to components, but I'd like a backup for ux_icon() as well, or at least a way to ignore it, since usually icons are a bonus. I love ux_icons, I got rid of including all of fontawesome and bootstrap-icons and my attempts to normalize them.

BUT before I could do and it would gracefully fail. Now it throws an error.

@smnandre
Copy link
Member

We won't use the guard tag as it is really destined to rare cases (see original issue) where a bundle may need two options for certain filters / functions depending on the parent app choices.

Regarding the component existence, we cannot and won't do it in 2.x. But this is absolutely something i'd like to have in 3.x.

@smnandre smnandre changed the title Test if component exists (guard?) [TwigComponent] Test if component exists (guard?) Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants