diff --git a/doc/api.rst b/doc/api.rst index d910530ae..a58afb2b7 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -126,6 +126,18 @@ default variables for that resolution, which the render context can override:: Pass the same context to ``hasBlock()``, ``getBlockNames()`` and ``renderBlock()`` to keep them consistent. +A chain also accepts other chains:: + + $base = new BlockChain($twig, ['base_theme.html.twig']); + $application = new BlockChain($twig, ['application_theme.html.twig', $base]); + $admin = new BlockChain($twig, ['admin_theme.html.twig', $application]); + +A chained chain keeps its position in the precedence order: templates listed +before it win, and it wins over templates listed after it. It contributes the +blocks it composes itself, resolved with its own default variables. Chaining a +chain never modifies it, so the same chain can be reused in as many others as +needed. + Streaming Templates ------------------- diff --git a/src/BlockChain.php b/src/BlockChain.php index e68f145da..81d0a7105 100644 --- a/src/BlockChain.php +++ b/src/BlockChain.php @@ -18,10 +18,10 @@ use Twig\Error\RuntimeError; */ final class BlockChain { - /** @var list