ThinkPHP5.0 templates

Source: Internet
Author: User

ThinkPHP5.0 Template Template Rendering
    1. The default view directory is the view directory under the default module
    2. Render rule: Call the \think\view class fetch method
// [模板文件目录]/当前控制器名(小写+下划线)/当前操作名(小写).htmlreturn $view->fetch();// [模板文件目录]/当前控制器名(小写+下划线)/add.htmlreturn $view->fetch(‘add‘);return $view->fetch(‘user/add‘);
Template configuration
// config.php 中配置‘template‘  =>  [    ‘layout_on‘ =>  true,    ‘layout_name‘ =>  ‘layout‘,    // 模板引擎    ‘type‘ => ‘think‘,    // 普通标签开始标记     ‘tpl_begin‘ => ‘<{‘,    // 普通标签结束标记    ‘tpl_end‘ => ‘}>‘]
Variable assignment in Controller
$this->assgin(‘list‘, $list);$view = new View();$view->name = ‘thinkphp‘;return $view->fetch();$this->fetch(‘view‘,[    ‘list‘ => $list])
Function
// 加密{$data.name|md5} // 时间{$create_time|date="y-m-d",###}// 截取字符串{$data.name|substr=0,3}// 多个函数操作过滤{$name|md5|strtoupper|substr=0,3}// 默认值{$user.nickname|default="这家伙很懒,什么也没留下"}
Operation (Ternary)
{$status? ‘正常‘ : ‘错误‘}{$info[‘status‘]? $info[‘msg‘] : $info[‘error‘]}{$info.status? $info.msg : $info.error }{$varname.aa ?? ‘xxx‘}
Built-in label loops
//Volist标签的name属性表示模板赋值的变量名称,因此不可随意在模板文件中改变。id表示当前的循环变量,可以随意指定{volist name=‘dataname’ id =‘value‘}    {$value.id}{/volist}// 如果需要分页,也可以再标签中操作,offset为开始条数 length为获取条数{volist name="list" id="vo" offset="5" length=‘10‘}    {$vo.name}{/volist}// 还可以设置限制,mod 为偶数{volist name="list" id="vo" mod="2" }    {eq name="mod" value="1"}{$vo.name}{/eq}{/volist}// 还可以设置限制,empty为空是输出值,empty属性不支持直接传入html语法,但可以支持变量输出{volist name="list" id="vo" empty="空空如也" }    {eq name="mod" value="1"}{$vo.name}{/eq}{/volist}// foreach{foreach name="list" item="vo"}    {$vo.id}:{$vo.name}{/foreach}// for{for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" }
Conditions
比较标签eq或者 equal  等于neq 或者notequal  不等于gt  大于egt 大于等于lt  小于elt 小于等于heq 恒等于nheq    不恒等于// switch{switch name="变量" }    // 支持多个格式判断    {case value="gif|png|jpg"}图像格式{/case}    {case value="值1" break="0或1"}输出内容1{/case}    {case value="值2"}输出内容2{/case}    {default /}默认情况{/switch}// if{if condition="($name == 1) OR ($name > 100) "}      value1{elseif condition="$name eq 2"/}    value2{else /}    value3{/if}// in{in name="id" value="1,2,3"}    id在范围内{/in}{notin name="id" value="1,2,3"}    id不在范围内{/notin}// between 变量的值可以是字符串或者数组,还可以支持系统变量。value只需要一个区间范围,也就是只支持两个值,后面的值无效{between name="id" value="1,10"}输出内容1{/between}

ThinkPHP5.0 templates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.