Can i use {plink} as n:macro
Notice: This thread is very old.
- amik
- Member | 118
Hi,
is there any option to write the {plink} as n:macro, for writing presenter links
inside components?
I use n:href in all <a> tags, so, in the several occasions when I need
to link a presenter from inside a component, do I have to use
href=“{plink}”? It kindof makes the way of writing links inconsistent.
Thanks.
- Patrik Votoček
- Member | 2221
Hi,
in native Nette package is not supported but you can write your own “phref”
n macro.
something like this:
<?php
namespace App;
use Nette,
Latte,
Latte\MacroNode,
Latte\PhpWriter;
class UIMacros extends Latte\Macros\MacroSet
{
public static function install(Latte\Compiler $compiler)
{
$me->addMacro('phref', NULL, NULL, function(MacroNode $node, PhpWriter $writer) use ($me) {
return ' ?> href="<?php ' . $me->macroLink($node, $writer) . ' ?>"<?php ';
});
}
/********************* macros ****************d*g**/
/**
* n:phref="destination [,] [params]"
*/
public function macroLink(MacroNode $node, PhpWriter $writer)
{
$node->modifiers = preg_replace('#\|safeurl\s*(?=\||\z)#i', '', $node->modifiers);
return $writer->using($node, $this->getCompiler())
->write('echo %escape(%modify($_presenter->link(%node.word, %node.array?)))');
}
}