gpt4 book ai didi

php - Nette Framework - 自定义属性宏

转载 作者:可可西里 更新时间:2023-11-01 12:47:07 24 4
gpt4 key购买 nike

Nette Framework 中定义新属性宏的最佳方法是什么? ?

另外,是否可以在配置文件中这样做?

最佳答案

在 Nette Framework 中定义自己的宏非常简单,首先你必须创建 MacroSet:

$latte = new Nette\Latte\Engine;
$set = new Nette\Latte\Macros\MacroSet($latte->compiler);

然后创建带有参数的新宏:

$set->addMacro('if', 'if (%node.args):', 'endif');

第二个问题的解决方案:

Class MyMacroSet extends Nette\Latte\Macros\MacroSet
{
public static function install(Nette\Latte\Compiler $compiler)
{
$compiler->addMacro('if', 'if (%node.args):', 'endif');
}
}

在 config.neon 中你可以注册你的 macroSet:

nette.latte:
setup:
- MyMacroSet::install($service->compiler)

关于php - Nette Framework - 自定义属性宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9456439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com