diff --git a/src/Twig/Node/DisplayEndNode.php b/src/Twig/Node/DisplayEndNode.php index 92c2848..c9c81c3 100644 --- a/src/Twig/Node/DisplayEndNode.php +++ b/src/Twig/Node/DisplayEndNode.php @@ -39,6 +39,10 @@ public function __construct(ModuleNode $module) */ public function compile(Compiler $compiler) { + if ($this->module->hasAttribute('is_embedded')) { + return; + } + $extension = Extension::class; $templateName = $this->getTemplateName(); $view = View::class; diff --git a/src/Twig/Node/DisplayStartNode.php b/src/Twig/Node/DisplayStartNode.php index ae825fa..6c60c4a 100644 --- a/src/Twig/Node/DisplayStartNode.php +++ b/src/Twig/Node/DisplayStartNode.php @@ -43,6 +43,10 @@ public function __construct(ModuleNode $module, FindPresentationModelInterface $ */ public function compile(Compiler $compiler) { + if ($this->module->hasAttribute('is_embedded')) { + return; + } + $presentationModel = $this->findPresentationModel->for($this->getTemplateName()); $compiler diff --git a/src/Twig/NodeVisitor/ModelNodeVisitor.php b/src/Twig/NodeVisitor/ModelNodeVisitor.php index c3c2615..30e01e1 100644 --- a/src/Twig/NodeVisitor/ModelNodeVisitor.php +++ b/src/Twig/NodeVisitor/ModelNodeVisitor.php @@ -52,6 +52,13 @@ public function leaveNode(Node $node, Environment $environment): Node return $node; } + if ($node->hasAttribute('embedded_templates')) { + /** @var ModuleNode $embeddedTemplate */ + foreach ($node->getAttribute('embedded_templates') as $embeddedTemplate) { + $embeddedTemplate->setAttribute('is_embedded', true); + } + } + $node->setNode('display_start', new DisplayStartNode($node, $this)); $node->setNode('display_end', new DisplayEndNode($node)); diff --git a/tests/Integration/Embedding/EmbeddingTest.php b/tests/Integration/Embedding/EmbeddingTest.php index 415a513..21da955 100644 --- a/tests/Integration/Embedding/EmbeddingTest.php +++ b/tests/Integration/Embedding/EmbeddingTest.php @@ -66,8 +66,6 @@ public function testEmbeddedTemplatesShouldReceiveVariablesPassedAsArguments() */ public function testPresentersShouldOnlyBeCalledOnce() { - $this->markTestSkipped('Presenters should only be called once: currently fails, fix pending.'); - $this->pagePresenter ->expects($this->once()) ->method('present'); diff --git a/tests/Integration/Embedding/Templates/page.twig b/tests/Integration/Embedding/Templates/page.twig index 19854d5..51b2d62 100644 --- a/tests/Integration/Embedding/Templates/page.twig +++ b/tests/Integration/Embedding/Templates/page.twig @@ -1,7 +1,7 @@ {% model 'Shoot\\Shoot\\Tests\\Integration\\Embedding\\Models\\Page' %} {% extends 'base.twig' %} {% block body %} - {% embed 'layout.twig' with { main_class: 'main--overriden'} only %} + {% embed 'layout.twig' with { main_class: 'main--overriden'} %} {% block main %}

{{ title }}

{{ content }}