当前位置:网站首页>(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
边栏推荐
猜你喜欢

1.10今日学习

第一次手撕代码,如何解出全排列问题

12.什么是JS

URL URL

1.uview form校验位置可以改变 2.时间区间

DOM manipulation---magnifying glass case

微信小程序自定义swiper轮播图面板指示点|小圆点|进度条

Living to detect the Adaptive Normalized Representation Learning for GeneralizableFace Anti - Spoofing reading notes
![[league/climate]一个功能健全的命令行功能操作库](/img/ce/39114b1c74af649223db97e5b0e29c.png)
[league/climate]一个功能健全的命令行功能操作库

SQL分类、DQL(数据查询语言)、以及相应SQL查询语句演示
随机推荐
js 中this指向
5.19今日学习
clock tick marks
每日五道面试题总结 22/7/23
PHP入门(自学笔记)
---static page---
Advanced Operations on Arrays
DOM manipulation---magnifying glass case
关于tp的apache 的.htaccess文件
第一次手撕代码,如何解出全排列问题
SQL分类、DQL(数据查询语言)、以及相应SQL查询语句演示
Batch replace file fonts, Simplified -> Traditional
(8) requests、os、sys、re、_thread
Various ways of AES encryption
4.14到新公司的一天
docker中配置mysql 5.7
The Error in the render: "TypeError: always read the properties of null '0' (reading)" Error solution
线程池(线程池介绍与使用)
PHP8.2将会有哪些新东西?
一分种一起来了解Vite的基础