Created
February 16, 2016 23:46
-
-
Save lucien144/933dc0c54031b185c76e to your computer and use it in GitHub Desktop.
Nette Latte macro: ifCurrentIn (array)
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 content} | |
{ifCurrentIn "Page:default", "Homepage:default"} | |
Hello, standart macro | |
{/ifCurrentIn} | |
<div n:ifCurrentIn="'Page:default', 'Homepage:default'"> | |
Hello, n:macro | |
</div> | |
{/block} |
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 | |
/** | |
* 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