Skip to content

Best way to use services into twig ? #50523

Answered by George-Gabro
a-vallet asked this question in Q&A
Discussion options

You must be logged in to vote

You can still use extentions but don't put any logical functions in them (services etc), instead make a new file that lazy load your logical functions that extends from "RuntimeExtensionInterface". Don't forget to register your "RuntimeExtension" in services.yaml as "twig.runtime"

This will lazy load the functions that you call from twig files instead of letting symfony load every single extension before loading any page

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@George-Gabro
Comment options

@a-vallet
Comment options

@George-Gabro
Comment options

Answer selected by a-vallet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants