当前位置:网站首页>(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
边栏推荐
猜你喜欢
随机推荐
When PHP initiates Alipay payment, the order information is garbled and solved
js的“类数组”及“类数组转数组”
4.PHP数组与数组排序
微信小程序怎么批量生成带参数的小程序码?
v-bind用法:类动态绑定对象 数组 style样式 及函数方法
TypeScript 错误 error TS2469、error TS2731 解决办法
数组的高级操作
uniapp | 使用npm update更新后编译报错问题
__dirname
JS对象, 函数和作用域
PHP的几个有趣的打开方式:从基本到变态
6.24今日学习
微信小程序云开发之模糊搜索
多线程(实现多线程、线程同步、生产者消费者)
v-on基本使用、参数传递、修饰词
Query the indexes of all tables in the database and parse them into sql
Various ways of AES encryption
1.6一些今日学习
13.JS输出内容和语法
一分种一起来了解Vite的基础








