-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from pattern-lab/fix-twig-embed
Fix broken Twig embed
- Loading branch information
Showing
5 changed files
with
76 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace PatternLab\PatternEngine\Twig; | ||
|
||
class PatternDataEmbedNode extends \Twig_Node_Embed | ||
{ | ||
use PatternDataNodeTrait; | ||
|
||
public function __construct(\Twig_Node_Embed $originalNode, $data) | ||
{ | ||
parent::__construct( | ||
$originalNode->getAttribute('filename'), | ||
$originalNode->getAttribute('index'), | ||
$originalNode->getNode('variables'), | ||
$originalNode->getAttribute('only'), | ||
$originalNode->getAttribute('ignore_missing'), | ||
$originalNode->getLine(), | ||
$originalNode->getNodeTag() | ||
); | ||
|
||
$this->data = $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace PatternLab\PatternEngine\Twig; | ||
|
||
trait PatternDataNodeTrait | ||
{ | ||
protected $data; | ||
|
||
protected function addTemplateArguments(\Twig_Compiler $compiler) | ||
{ | ||
if (null === $this->getNode('variables')) { | ||
if (false === $this->getAttribute('only')) { | ||
$compiler | ||
->raw('array_merge($context, ') | ||
->repr($this->data) | ||
->raw(')') | ||
; | ||
} | ||
else { | ||
$compiler->raw('array()'); | ||
} | ||
} elseif (false === $this->getAttribute('only')) { | ||
$compiler | ||
->raw('array_merge($context, ') | ||
->repr($this->data) | ||
->raw(', ') | ||
->subcompile($this->getNode('variables')) | ||
->raw(')') | ||
; | ||
} else { | ||
$compiler->subcompile($this->getNode('variables')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters