美文网首页
微擎模板引擎

微擎模板引擎

作者: StevenQin | 来源:发表于2019-04-24 18:04 被阅读0次

    $this->template('xxx')说明

    类似smarty模板引擎

    include $this->template('index')
    

    1、如果写在模块的前台方法function doMobileIndex(){}
    模板文件的目录为:/addons/xxx应用目录/template/mobile/index.html
    2、如果写在模块的后台方法function doWebIndex(){}中,模板文件的目录为:/addons/应用目录/template/index.html

    输出变量

    • 前台方法
        public function doMobileIndex()
        {
            //这个操作被定义用来呈现 功能封面
            global $_W, $_GPC;
            $name="Steven Qin";
            include $this->template('index');
        }
    
    • 模板
    输出变量是:{$name}
    
    • 触发路由 (MVC格式)
    [http://mall.raycare.net/app/index.php?i=5&c=entry&do=index&m=health_moniter](http://mall.raycare.net/app/index.php?i=5&c=entry&do=index&m=health_moniter)
    

    循环

    • 前台方法
     $arr = ['周一','周二','周三','周四','周五'];
    
    • 模板文件
    循环输出变量:<br/>
    {loop $arr $index $row}
      {php echo $index + 1;} => {$row} <br/>
    {/loop}
    

    条件语句

    https://s.w7.cc/index.php?c=wiki&do=view&id=1&list=190

    {if condition}
       {elseif condition}
       {else}
    {/if}
    

    php代码

    {php echo '这样就可以写php代码了';}
    

    url

    <a href="{php echo $this->createMobileUrl('xinxi');}">跳转信息</a>
    

    生成url如下:
    http://mall.raycare.net/app/index.php?i=5&c=entry&do=xinxi&m=health_moniter

    调用模板

    {template '模板文件名不带后缀'}
    

    前台方法默认在addons/template/mobile下面
    后台方法默认在addons/template下面

    相关文章

      网友评论

          本文标题:微擎模板引擎

          本文链接:https://www.haomeiwen.com/subject/wmhngqtx.html