From 207f8737392b4856734780f3accef76f2cfc9fd6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 27 Aug 2026 13:07:13 +0200 Subject: [PATCH] Document that include_only keeps global variables available --- doc/functions/include_only.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/functions/include_only.rst b/doc/functions/include_only.rst index be3ffe9a6..ab1399559 100644 --- a/doc/functions/include_only.rst +++ b/doc/functions/include_only.rst @@ -17,6 +17,9 @@ Variables from the active context are not passed implicitly. This makes the data a template relies on explicit, which is often clearer and easier to reason about. +Note that global variables (like the ones registered via ``addGlobal()``) are +not part of the context: they remain available in the included template. + Returned Value -------------- @@ -40,7 +43,7 @@ explicitly: .. code-block:: twig - {# template.html.twig will only have access to the "name" variable #} + {# template.html.twig only gets the "name" variable from the caller #} {{ include_only('template.html.twig', {name: 'Fabien'}) }} When passing a variable from the current context, you can use the following