Skip to content

Symfony: expose public members of #[AsTwigComponent] classes to templates#366

Merged
janedbal merged 1 commit into
masterfrom
twig-component-public-members
May 28, 2026
Merged

Symfony: expose public members of #[AsTwigComponent] classes to templates#366
janedbal merged 1 commit into
masterfrom
twig-component-public-members

Conversation

@janedbal
Copy link
Copy Markdown
Member

Summary

  • Twig components render with this bound to the component instance, so every public property and method is reachable from the template (e.g. {{ this.getTranslatedTitle() }}) — previously we required #[ExposeInTemplate] and reported such members as dead otherwise.
  • Now SymfonyUsageProvider routes #[AsTwigComponent] / #[AsLiveComponent] classes through the existing TemplateViewDataTraverser, the same machinery used for data passed to render(). Public members (and the classes they return) are marked as used.

Fixes #364

Co-Authored-By: Claude Code

…ates

Twig components render their template with `this` bound to the
component instance, so every public property and method is reachable
from the template (e.g. `{{ this.getTranslatedTitle() }}`). Run such
classes through TemplateViewDataTraverser, the same machinery used
for data passed to render(), instead of requiring #[ExposeInTemplate].

Fixes #364

Co-Authored-By: Claude Code
@janedbal janedbal force-pushed the twig-component-public-members branch from 6a32cdc to 8a54227 Compare May 28, 2026 11:04
@janedbal janedbal merged commit 0d2dac4 into master May 28, 2026
32 checks passed
@janedbal janedbal deleted the twig-component-public-members branch May 28, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Twig component methods

1 participant