php – Nette Framework – 自定义属性宏

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Nette Framework – 自定义属性宏脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Nette Framework中定义新属性宏的最佳方法是什么

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

在Nette Framework中定义自己的宏非常简单,
首先,您必须创建MacroSet:
$latte = new Nette\Latte\Engine;
$set = new Nette\Latte\Macros\MacroSet($latte->compiler);

然后用args创建新的宏:

$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','endif');
    }
}

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

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

脚本宝典总结

以上是脚本宝典为你收集整理的php – Nette Framework – 自定义属性宏全部内容,希望文章能够帮你解决php – Nette Framework – 自定义属性宏所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。