Skip to content

Instantly share code, notes, and snippets.

@lucien144
Created February 16, 2016 23:46
Show Gist options
  • Save lucien144/933dc0c54031b185c76e to your computer and use it in GitHub Desktop.
Save lucien144/933dc0c54031b185c76e to your computer and use it in GitHub Desktop.
Nette Latte macro: ifCurrentIn (array)
{block content}
{ifCurrentIn "Page:default", "Homepage:default"}
Hello, standart macro
{/ifCurrentIn}
<div n:ifCurrentIn="'Page:default', 'Homepage:default'">
Hello, n:macro
</div>
{/block}
<?php
/**
* Homepage presenter.
*
* @author John Doe
* @package MyApplication
*/
class HomepagePresenter extends BasePresenter
{
public function templatePrepareFilters($template)
{
$latte = $template->getLatte();
$macroSet = new \Latte\Macros\MacroSet($template->getLatte()->getCompiler());
$macroSet->addMacro('ifCurrentIn', function($node, $writer)
{
return $writer->write('foreach (%node.array as $l) { if ($_presenter->isLinkCurrent($l)) { $_c = true; break; }} if (isset($_c)): ');
}, 'endif; unset($_c);');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment