Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created February 11, 2016 19:10
Show Gist options
  • Save fprochazka/756ab3005e5d4a750db4 to your computer and use it in GitHub Desktop.
Save fprochazka/756ab3005e5d4a750db4 to your computer and use it in GitHub Desktop.
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