duannuo7878 2012-02-26 19:34
浏览 23
已采纳

Nette Framework - 自定义属性宏

What is the best way to define new attribute macros in the Nette Framework?

Moreover, would it be possible to do so in the config file?

  • 写回答

1条回答 默认 最新

  • doudu9148 2012-02-26 21:19
    关注

    define your own macro is really simple in Nette Framework, first you must create MacroSet:

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

    then create new Macro with args:

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

    And solution for your second question:

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

    and in config.neon you can register your macroSet:

    nette.latte:
                    setup:
                            - MyMacroSet::install($service->compiler)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程