zoukankan      html  css  js  c++  java
  • 四、smarty模板的自定义函数

    smarty模板的自定义函数(这里介绍的是常用)

    分为三个种类:

    1、  变量调节器

    2、  函数

    3、  块函数

    三个种类插件的用法:

    1、  变量调解器的用法,

    <{$var|myfun:arg1:arg2}>

    2、  函数的用法(和使用HTML标记很像)

    如,

    <{myfun color=”red” size=”7” num=”7”}>

    在PHP中定义的函数为:

    $smarty->registerPlugin(“function”,”myfun”,”one”);
    
    function one($args,$smarty){}   //$args为color=”red” size=”7” num=”7”这些参数组合起来的关联数组,第二个参数是自动接收$smarty对象的,如果不用可不写

    3、  块函数的用法,

    如,

    <{myfun color=”red” size=”7”}>内容<{/myfun}>

    在PHP中定义的函数为:

    $smarty->registerPlugin(“block”,”myfun”,”two”)
    
    Function two($args,$content,$smarty){}   //$args为color=”red” size=”7”这些参数组合起来的关联数组,第二个参数是要显示的”内容”,第三个参数是$smarty对象

    有两种做法:

    1、  使用smarty对象中的registerPlugin()方法将PHP中的函数注册成smarty中的函数。

    2、  就是开发的smarty的插件(以独立的特定文件添加插件)

          1)  声明的位置

          可以在smarty类库中的原有Plugins目录下创建,也可以使用自己指定的目录$smarty->addPluginsDir(目录)   //smarty3中

          2)  文件的命名

          修改器,modifier.修改器名称.php

          函数,  function.函数名称.php

          块函数,block.块函数名称.php

          3)  函数的命名

          修改器,smarty_modifier_修改器名称()

          函数,  smarty_function_函数名称()

          块函数,smarty_block_块函数名称()

          4)  参数的规则

          修改器,smarty_modifier_修改器名称($var,$arg1,$arg2,$arg3)

          函数,  smarty_function_函数名称($args,$smarty)

          块函数,smarty_block_块函数($args,$content,$smarty,$repeat)

          //$repeat参数防止块函数被重复调用,及第一次调用为真,以后为假

          //<{myfun color=”red” size=”7”}>内容<{/myfun}>,第一次myfun为真,第二次<{/myfun}>为假

  • 相关阅读:
    iOS10权限声明国际化
    用"僵尸对象"调试内存管理问题
    windows系统下的两个批处理命令
    解决windows系统下打开应用弹出丢失libmysql.dll的问题
    简单的cocos2dx笔试题
    解决cocos2dx 3.x 导入cocostudio的ui界面出现错位问题
    mac 使用homebrew 安装mysql
    cocos2dx for lua 简单的翻牌动画
    cocos2dx for lua A*寻路算法实现2
    解决升级mac os X EI Capitan后遇到LibclangError: dlopen(libclang.dylib, 6): image not found.的问题
  • 原文地址:https://www.cnblogs.com/yxpblog/p/4222661.html
Copyright © 2011-2022 走看看