Skip to content
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

[Question] Alternative of base_template_class option for twig V3 #3712

Closed
z3niths opened this issue Jun 8, 2022 · 1 comment
Closed

[Question] Alternative of base_template_class option for twig V3 #3712

z3niths opened this issue Jun 8, 2022 · 1 comment

Comments

@z3niths
Copy link

z3niths commented Jun 8, 2022

I've posted the question here but no answer yet.
https://stackoverflow.com/questions/72513154/alternative-of-base-template-class-php-twig-template

Basically, I used to extend the env class and add a new variable to keep tracking all the rendered templates to use the list later for CSS purge (Removing unused CSS). but without base_template_class option on the V3 I cannot do that anymore because I cannot use the custom template to call the tracking function I've prepared in the Environment class.

What I can do to preserve the similar behavior I have done in the custom template classes.

Sorry if it's not the right channel.

@stof
Copy link
Member

stof commented Jun 8, 2022

You can use a node visitor to inject custom nodes adding logic at the beginning or the end of the rendering of a template. See the ProfilerExtension for an example.
This solution is strictly superior to changing the base class (as multiple extensions can use this extension point at the same time, while we cannot have multiple base classes). And it also works in Twig 1 and 2.

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

No branches or pull requests

3 participants