diff --git a/src/Latte/Macros/BlockMacros.php b/src/Latte/Macros/BlockMacros.php index c7e7ef739..abb729653 100644 --- a/src/Latte/Macros/BlockMacros.php +++ b/src/Latte/Macros/BlockMacros.php @@ -22,6 +22,9 @@ */ class BlockMacros extends MacroSet { + /** @var string */ + public $snippetAttribute = 'id'; + /** @var array */ private $namedBlocks = []; @@ -240,12 +243,12 @@ public function macroBlock(MacroNode $node, PhpWriter $writer) $enterCode = '$this->global->snippetDriver->enter(' . $writer->formatWord($name) . ', "' . SnippetDriver::TYPE_DYNAMIC . '");'; if ($node->prefix) { - $node->attrCode = $writer->write("global->snippetDriver->getHtmlId({$writer->formatWord($name)})) . '\"' ?>"); + $node->attrCode = $writer->write("snippetAttribute=\"' . htmlSpecialChars(\$this->global->snippetDriver->getHtmlId({$writer->formatWord($name)})) . '\"' ?>"); return $writer->write($enterCode); } $node->closingCode .= "\n"; $this->checkExtraArgs($node); - return $writer->write("?>\n
global->snippetDriver->getHtmlId({$writer->formatWord($name)})) ?>\">write("?>\n
snippetAttribute=\"global->snippetDriver->getHtmlId({$writer->formatWord($name)})) ?>\">data->leave = true; @@ -275,8 +278,8 @@ public function macroBlock(MacroNode $node, PhpWriter $writer) // static snippet/snippetArea if ($node->name === 'snippet' || $node->name === 'snippetArea') { - if ($node->prefix && isset($node->htmlNode->attrs['id'])) { - throw new CompileException('Cannot combine HTML attribute id with n:snippet.'); + if ($node->prefix && isset($node->htmlNode->attrs[$this->snippetAttribute])) { + throw new CompileException("Cannot combine HTML attribute $this->snippetAttribute with n:snippet."); } $node->data->name = $name = '_' . $name; } @@ -306,11 +309,11 @@ public function macroBlock(MacroNode $node, PhpWriter $writer) if (isset($node->htmlNode->macroAttrs['foreach'])) { trigger_error('Combination of n:snippet with n:foreach is invalid, use n:inner-foreach.', E_USER_WARNING); } - $node->attrCode = $writer->write('global->snippetDriver->getHtmlId(%var)) . \'"\' ?>', (string) substr($name, 1)); + $node->attrCode = $writer->write("snippetAttribute=\"' . htmlSpecialChars(\$this->global->snippetDriver->getHtmlId(%var)) . '\"' ?>", (string) substr($name, 1)); return $writer->write($include, $name); } $this->checkExtraArgs($node); - return $writer->write("?>\n
global->snippetDriver->getHtmlId(%var)) ?>\">\n
write("?>\n
snippetAttribute=\"global->snippetDriver->getHtmlId(%var)) ?>\">\n