Vyrenderování jednoho bloku z latte šablony
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
<?php | |
use Latte; | |
use Latte\Compiler; | |
class RenderBlockHelperMacro extends \Latte\Macros\MacroSet | |
{ | |
public function __construct(Compiler $compiler) | |
{ | |
parent::__construct($compiler); | |
$this->addMacro('render-block-macro-helper', 'throw new \Exception()'); | |
} | |
public function finalize() | |
{ | |
$prolog = []; | |
$prolog[] = 'if (!empty($_overrideBlockRendering)) {'; | |
$prolog[] = "\t" . 'call_user_func(reset($_b->blocks[$_overrideBlockRendering]), $_b, get_defined_vars());'; | |
$prolog[] = "\t" . 'return; // end rendering'; | |
$prolog[] = '}'; | |
return [implode("\n", $prolog), ""]; | |
} | |
} |
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
{block subject}foo{/block} | |
{block body} |
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
<?php | |
$engine = new Engine(); | |
$engine->onCompile[] = function (Engine $engine) { | |
new RenderBlockHelperMacro($engine->getCompiler()); | |
}; | |
$subject = $engine->renderToString(__DIR__ . '/template.latte', [ | |
'_overrideBlockRendering' => 'subject'; | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment