-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
[TwigComponents] [Question] Render component using dynamically passed name #1922
Comments
Do you have an error or something when executing this? You can also do this: {% set my_string = 'Modal' %}
{{ component(my_string, {
type: 'success',
content: ...content
}) but here you need to have your content in a props. |
@WebMamba is right, the only way to call component dynamically is with the component function. Currently there is no possibility to embed content into components with dynamic name. |
Maybe we could take inspiration from this: https://laravel.com/docs/11.x/blade#dynamic-components |
You can call dynamic component already. It's embedding a component that does not work |
Sorry! |
Inspired by what @seb-jean said, we could perhaps create a Without content: {% set component_name = 'Modal' %}
<twig:ux:dynamic-component component="{{ component_name }}" /> With content: {% set component_name = 'Modal' %}
<twig:ux:dynamic-component component="{{ component_name }}">
{{ block(outerBlocks.content) }}
</twig:ux:dynamic-component> So the content can be passed with dynamic component names. |
This is not the real problem, for now the component tag does not allow dynamic bloc names. The HTML syntax is only sugar on top of it |
Hi,
I'm trying to render a Twig component using a dynamically passed name. Is there a way to achieve this in Twig? Here is an example of what I'm attempting to do:
I want to be able to dynamically set the component name using the my_string variable. Any guidance or suggestions on how to accomplish this would be greatly appreciated!
Thank you!
The text was updated successfully, but these errors were encountered: