当前位置:网站首页>(2) Thinkphp6 template engine ** tag
(2) Thinkphp6 template engine ** tag
2022-08-02 03:54:00 【stealth rookie】
原生PHP · ThinkPHP5.0完全开发手册 · 看云
目录
普通标签
1.运算符
| 运算符 | 示例 |
|---|---|
| + | {$a+$b} |
| - | {$a-$b} |
| * | {$a*$b} |
| / | {$a/$b} |
| % | {$a%$b} |
| ++ | {$a++} 或 {++$a} |
| -- | {$a--} 或{--$a} |
| 综合运算 | {$a+$b*10+$c} |
| 三元运算符 | {$a==$b ? 'yes' : 'no'} |
controller文件
public function index(){
Vlew::assign('a',520);
View::assign("b',13);
return view::fetch();
}view文件
<div>{$a+$b}</div>
<dlv>{$a-$b}</div>
<div>{$a*$b}</div>
<div>{$a/$b}</div>
<div>{$a%$b}</div>
<div>{$a++}</div>
<div>{$a--}</div>
<div>{--$a}</div>
<div>{$c ? '存在' : '不存在'}</div>注:如果在$a前有空格,will not be calculated
2.模板函数
| 方法 | 描述 |
|---|---|
| date | 日期格式化(支持各种时间类型) |
| format | 字符串格式化 |
| upper | 转换为大写 |
| lower | 转换为小写 |
| first | 输出数组的第一个元素 |
| last | 输出数组的最后一个元素 |
| default | 默认值 |
| raw | 不使用(默认)转义 |
| md5 | md5加密 |
| substr | 截取字符串 |


3.注释
Template annotations support the annotation feature,The note text will not be displayed on the final page,For template maker reference and identification only
单行注释格式:{/* 注释内容 */}或{// 注释内容}
注意{和注释标记之间不能有空格.
多行注释格式:
{/* 这是模板
注释内容 */}
Note that template annotations are automatically removed after generating the compile cache backend,这一点和Html的注释不同
4.原样输出
原样输出: <literal></literal>
例:<div> <literal>{$default|default="小明"}</literal></div>
输出为{$default|default="小明"}
循环标签
1.foreach循环标签
foreach标签的用法和PHP语法相近,用于循环输出数组或者对象的属性
controller文件
public functlon index(){
$arr=[
[
'1d'>1,
"name'=>'小鱼'
],
[
'1d'=>2,
'name'=>'小虾 '
],
[
'1d'=>3,
'name'=>'小黄 '
]
];
Vlew::assign('arr',$arr); //全局变量赋值
return View::fetch(); //fetch 方法渲染页面
}view文件
{foreach $arr as $v}
<dlv>
<span>ID:{$v['id']}</span>
<span>姓名:{$v['name']}</span>
</div>
(/foreach)2.volist循环标签
- 二维数组的结果输出
name模板赋值的变量名称id当前的循环变量,可以随意起名key下标,从1开始,默认变量ioffset开始行数length获取行数empty如果数据为空,显示此文字
view文件
{volist name="arr" id="v" key="k" offset="1" length="2"}
<div>
<span>ID:{$v['id']}</span>
<span>姓名:{$v['name']}</span>
<span>下标:{$k}</span>
</div>
{/volist}3.for循环标签
for标签用法和PHP语法相近
{for start="开始值" end="结束值" comparison="" step="Burden value" name="循环变量名"}
{/for}
开始值,结束值、Both step values and loop variables can support variables,Start and end values are required,其他是可选,comparison的默认值是it,name的默认值是i,The default value for step value is 1,举例如下:
{for start="1" end="100"}
{$i}
{/for}The parsed code is just that
for ($i=1;$i<100;$1+=1){
echo $i;
}
判断标签
1.if判断标签
if标签的用法和PHP语法相近,用于条件判断
controller文件
public function index(){
view::assign('status',1);
View::assign('week',3);
return View::fetch();
}view文件
{if $status==1}
<div>开启</div>
{/if}
{if $status==0}
<div>关闭</div>
{else/}
<div>开启</div>
{/1f}
{if Sweek==0)
<div>星期日</div>
{elseif $week==1/}
<div>星期一</div>
{elseif $week==2/}
<div>星期二</div>
{elseif $week ==3/}
<div>星期三</div>
{elseif $week==4/}
<div>星期四</div>
{elseif $week == 5/}
<div>星期五</div>
{elseif Sweek =- 6/}
<div>星期六</div>
{/1f}2.switch判断标签
switch标签的用法和PHP相近,用于条件判断
{switch $week}
{case 0 }<div>星期日</div>{/case}
{case 1 }<div>星期一</div>{/case}
{case 2 }<div>星期二</div>{/case}
{case 3 }<div>星期三</div>{/case}
{case 4 }<div>星期四</div>{/case}
{/switch}其他标签
| 标签 | 描述 |
|---|---|
| in | Determines whether a variable has some value |
| notin | Determines whether a variable does not have some value |
| between | Determines whether a variable has some value |
| notbetween | Determines whether a variable does not have certain range values |
| present | Determine if a variable is 已定义 |
| notpresent | Determine if a variable is 未定义 |
| empty | Determine if a variable is为空 |
| notempty | Check if a variable is not null |
| defined | Determine whether a constant is 已定义 |
| notdefined | Determine whether a constant is 未定义 |
{php} echo "小明" {/php} #phpThe syntax in the middle of the tag is consideredphp解析,把phpRemove it and output it as it is
边栏推荐
猜你喜欢
随机推荐
微信小程序全局组件的定义
微信小程序九宫格抽奖和转盘抽奖的实现
IO streams, byte stream and byte stream buffer
[trendsoft/capital]金额转中文大写库
canvas--pie chart
正则笔记(2)- 正则表达式位置匹配攻略
npm and package.json
ES6迭代器解释举例
由中序遍历和前序遍历得到后序遍历(树的遍历)
6.24今日学习
微信小程序自定义swiper轮播图面板指示点|小圆点|进度条
js eventLoop 事件循环机制
TCP communications program
二维码生成API接口,可以直接作为A标签连接
3.PHP数据类型、常量、字符串和运算符
1.初识PHP
4.14到新公司的一天
ES6三点运算符、数组方法、字符串扩展方法
js 原型和原型链
5.19今日学习









