Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vyrenderování jednoho bloku z latte šablony
<?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), ""];
}
}
{block subject}foo{/block}
{block body}
<?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
You can’t perform that action at this time.