Skip to content

[TwigComponent] Add dynamic component name support#3699

Open
seb-jean wants to merge 1 commit into
symfony:3.xfrom
seb-jean:dynamic-component
Open

[TwigComponent] Add dynamic component name support#3699
seb-jean wants to merge 1 commit into
symfony:3.xfrom
seb-jean:dynamic-component

Conversation

@seb-jean

@seb-jean seb-jean commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? yes
Issues Fix #2905 / #3395
License MIT

Add support for dynamic component names in the {% component %} tag, in the HTML-like syntax using <twig:component>, and in the component() function.

{% component %} tag syntax

{# Dynamic variable (must be wrapped in parentheses) #}
{% component (componentName) %}{% endcomponent %}

{# Dynamic expression #}
{% set prefix = 'DynamicNameComponent' %}
{% for i in 1..2 %}
    {% component (prefix ~ i) %}{% endcomponent %}
{% endfor %}

{# Component object #}
{% component (componentObject) %}{% endcomponent %}

HTML-like syntax

{# Static component name #}
<twig:component is="Alert" type="success" />

{# Dynamic component name #}
<twig:component :is="componentName" type="success" />

{# Dynamic with content (paired tag) #}
<twig:component :is="componentName" type="success">
    Content here
</twig:component>

{# Dynamic in a loop #}
{% set prefix = 'DynamicNameComponent' %}
{% for i in 1..2 %}
    <twig:component :is="prefix ~ i" />
{% endfor %}

component() function

{{ component(componentName, {type: 'success'}) }}

@carsonbot carsonbot added Documentation Improvements or additions to documentation Feature New Feature TwigComponent Status: Needs Review Needs to be reviewed labels Jul 8, 2026
@seb-jean
seb-jean force-pushed the dynamic-component branch from 7b9bac6 to 04f105f Compare July 8, 2026 14:15
@seb-jean
seb-jean force-pushed the dynamic-component branch from 04f105f to eac30e5 Compare July 8, 2026 14:16
@Kocal

Kocal commented Jul 8, 2026

Copy link
Copy Markdown
Member

The syntax for the component tag already exists no? Or the PR adding that behavior is still opened?

@seb-jean

seb-jean commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I'm referring to this PR: #3395, which is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Feature New Feature Status: Needs Review Needs to be reviewed TwigComponent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants