Feature idea: global setting to NOT pass context to include function/tag by default #3890
Replies: 3 comments
-
A global setting would make it hard to write templates shared in a library, as you would not know how the include tag and functions would behave when rendering your template. |
Beta Was this translation helpful? Give feedback.
-
Hi @stof, Thanks for the response! That's a fair point. Is it not also true of existing environment options, though, like In any case, if it isn't feasible then it isn't feasible. Maybe I can come up with a linting strategy to warn myself if I forget to exclude the context. |
Beta Was this translation helpful? Give feedback.
-
@MichaelAllenWarner , if you never want to pass the context to the include function / tag, you can probably write a node visitor that change the arguments of the include function nodes. You can take insipiration here, where the visitor target exactly the node that you need to target: Twig/src/NodeVisitor/OptimizerNodeVisitor.php Line 165 in aeeec9a |
Beta Was this translation helpful? Give feedback.
-
When I use the
include
tag/function, I always useonly
/with_context = false
, and I imagine that there are a lot of other developers who do the same.It would be nice to have a global setting (an environment option?) that would make this the default behavior, so that developers like me don't have to remember to use
only
/with_context = false
every time. With such a setting enabled, you could still pass in context withwith_context = true
for the function andwith _context|merge({})
for the tag.Beta Was this translation helpful? Give feedback.
All reactions