StringLoader includeblock
Notice: This thread is very old.
- tivvit
- Member | 36
Hi, is there any possibility to use includeblock from file with
StringLoader
?
i mean this:
$content = "{includeblock 'file.latte'}";
$template = $this->templateFactory->createTemplate($this);
$latte = $template->getLatte();
$latte->setLoader(new Latte\Loaders\StringLoader());
$out = $latte->renderToString($content, array());
- tivvit
- Member | 36
The example is simplified. Let's say that file.latte
is some
static menu, and I want to use that menu block in pages loaded from database,
but not in all of them and I was lazy to do another template for them.
I tried absolute path, with interesting result: the path is printed, but the
block is not loaded
- Machy8
- Member | 59
Have you tried some conditions in template?
{if $page === "somePage"}
<div id=myMenu ></div>
{/if}
Way using loader (not shure if it is the best):
class BasePresenter extends \Nette\Application\UI\Presenter
protected function createTemplate()
{
$template = parent::createTemplate();
$template->getLatte()->setLoader(new \Path\To\Loader($this));
return $template;
}
class YourLoader extends \Latte\Loaders\FileLoader
{
public function getContent ($file)
{
$content = parent::getContent($file);
// Some process here - remove block (maybe regular expression?)
// Return modified file content without the block you want to remove
return $compiled;
}
}
Last edited by Machy8 (2015-12-13 12:30)