-
-
Notifications
You must be signed in to change notification settings - Fork 315
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] A HtmlTag
meta-component to easily renders dynamic HTML tag / attributes
#940
Comments
Yes, I like the idea! I remember that @norkunas was doing something similar I ping you here in case you are interest by the topics. |
Or maybe we can simply use the HTML tag name as meta-component, but IDK how it can works if it's dynamic. |
For simplicity in components I define as <{{ element }}{{ attributes.defaults({ href })>
{% block content %}{% endblock %}
</{{ element }}> So if href is not set it won't be included in output |
I think this will be pretty simple once #802 is available. |
Thank you for this issue. |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
Yes and no, #1414 can fill the feature but is still opens |
Thank you for this issue. |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
Hi!
Sometimes, inside a Twig template, you need to render HTML with a dynamic tag or attributes, depending if variables/props are presents, depending of their values, etc...
Given the following template:
We can see that it is not easy to render a dynamic tag (you must think about the closing tag too), and you can't re-use
attributes
nor use a newComponentAttributes
instance (because you are not inside a Twig Component) to easily render tags.Currently you need to do it yourself and it can leads to inconsistency / bad readability.
With a new meta-component (which has no logic but to renders HTML), we can imagine passing a tag and HTML attributes as an object (think as a simplified
h
function):(The
_
prefix in_tag
is here to prevent a potential conflict with atag
HTML attribute, but maybe there is a better solution?)The template associated to this components would looks like this:
WDYT?
Thanks
The text was updated successfully, but these errors were encountered: