You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[TwigComponent] attributes.has() method
| Q | A
| ------------- | ---
| Bug fix? |no
| New feature? | yes
| Issues | -
| License | MIT
Provide a `ComponentAttributes::has()` function to be able to check via `{{ attributes.has('foo') }}` whether the attribute has been passed.
I would like to show the use case in the following example. Using `attributes.has('href')`, I check whether the TwigComponent has set an 'href' attribute when it is called. If so, an `<a>` tag should be rendered, otherwise a `<button>` tag.
```twig
{# templates/components/Button.html.twig #}
{% set element = attributes.has('href') ? 'a' : 'button' %}
<{{ element }} {{ attributes }}>
{% block content %}{% endblock %}
</{{ element }}>
```
Commits
-------
3718a12 [TwigComponent] attributes.has() method
0 commit comments