diff --git a/Compiler.php b/Compiler.php index 42886e9..c5a0c50 100644 --- a/Compiler.php +++ b/Compiler.php @@ -1889,10 +1889,9 @@ protected function compileElement(Node $node) $phtml = ''; - if (!$node->tag) - $node->tag = $this->options['default_tag']; + $tag = $this->interpolate($node->tag ?: $this->options['default_tag']); - $phtml .= "<{$node->tag}"; + $phtml .= "<{$tag}"; $htmlMode = $this->isHtml(); $xhtmlMode = $this->isXhtml(); @@ -2070,14 +2069,14 @@ protected function compileElement(Node $node) } $hasChildren = count($node->children) > 0; - $isSelfClosing = in_array($node->tag, $this->options['self_closing_tags']); + $isSelfClosing = in_array($tag, $this->options['self_closing_tags']); if (!$hasChildren && (!$htmlMode || !$isSelfClosing)) { if ($anyHtmlMode && !$isSelfClosing) { //Force closed tag in HTML - $phtml .= ">tag}>"; + $phtml .= ">"; return $phtml; } @@ -2093,7 +2092,7 @@ protected function compileElement(Node $node) return $phtml; $phtml .= $this->compileChildren($node->children); - $phtml .= $this->newLine().$this->indent()."tag}>"; + $phtml .= $this->newLine().$this->indent().""; return $phtml; } diff --git a/Lexer.php b/Lexer.php index 6ba2610..749339c 100644 --- a/Lexer.php +++ b/Lexer.php @@ -1511,7 +1511,7 @@ protected function scanDoctype() protected function scanTag() { - foreach ($this->scanToken('tag', '(?[a-zA-Z_][a-zA-Z0-9\-_]*)', 'i') as $token) { + foreach ($this->scanToken('tag', '(?(([a-zA-Z_][a-zA-Z0-9\-_]*)?[\?!#]\{[^\}]+\}([a-zA-Z_][a-zA-Z0-9\-_]*)?|[a-zA-Z_][a-zA-Z0-9\-_]*))', 'i') as $token) { yield $token; diff --git a/Test/InterpolationTest.php b/Test/InterpolationTest.php index 4fce415..c8a6b65 100644 --- a/Test/InterpolationTest.php +++ b/Test/InterpolationTest.php @@ -102,4 +102,12 @@ public function testIeConditionals() $this->assertEquals('', $this->renderer->compile("")); } + + public function testTagInterpolation() + { + + $this->assertEquals('< class="some-class">Some Content>', $this->renderer->compile("\$tagName='abcdefghi'\n#{\$tagName}.some-class Some Content")); + $this->assertEquals('ghi class="some-class">Some Contentghi>', $this->renderer->compile("\$tagName='def'\nabc#{\$tagName}ghi.some-class Some Content")); + + } } \ No newline at end of file