(thinkphp模板教程)(thinkphp用的什么模板引擎)

上一篇文章讲解“模型-内置标签之比较标签”,本篇文章讲解“模板-内置标签之条件标签一”。

条件标签

一、switch标签

(thinkphp模板教程)(thinkphp用的什么模板引擎)

1)基本用法

①在Index控制器中,新建switchtag方法

(thinkphp模板教程)(thinkphp用的什么模板引擎)

②新建switch.html模板,并使用switch标签进行输出

(thinkphp模板教程)(thinkphp用的什么模板引擎)

预览:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

2)使用函数或系统变量

在switch.html模板中,对数据使用变量:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

访问switchtag方法,预览:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

3)case属性支持多个条件的判断

对于case属性可以支持多个条件的判断,使用”|”进行分割。

在switch.html模板中,case使用多个条件:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

访问switchtag方法,预览:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

4)case的value属性可以使用变量

在switch.html模板中,case的value属性使用变量进行判断:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

访问switchtag方法,预览:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

注意:

1. 使用变量方式的情况下,不再支持“|”分割的多个条件判断用法。

2. case的value属性使用变量时,一定要加“$”。

二、if标签

(thinkphp模板教程)(thinkphp用的什么模板引擎)

1)基本用法

①在Index控制器中,新建iftag方法

(thinkphp模板教程)(thinkphp用的什么模板引擎)

②新建if.html模板,并在模板中用if标签判断

(thinkphp模板教程)(thinkphp用的什么模板引擎)

预览:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

2)使用PHP代码

在if.html模板中,使用PHP模板:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

访问iftag方法,预览:

(thinkphp模板教程)(thinkphp用的什么模板引擎)

注意:

1. 判断条件支持点语法($data.num)、对象语法($data->num)、数组下标($data[‘num’])。

2. 如果某些特殊的要求下面,IF标签仍然无法满足要求的话,可以使用原生php代码或者PHP标签来直接书写代码。

ThinkPHP5连载为卓象程序员原创,转载请联系卓象程序员

(thinkphp模板教程)(thinkphp用的什么模板引擎)

关注卓象程序员,定期发布技术文章

下一篇讲解“模板-内置标签之条件标签二”

(thinkphp模板教程)(thinkphp用的什么模板引擎)
(thinkphp模板教程)(thinkphp用的什么模板引擎)

声明:我要去上班所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,版权归原作者程序员小娇所有,原文出处。若您的权利被侵害,请联系删除。

本文标题:(thinkphp模板教程)(thinkphp用的什么模板引擎)
本文链接:https://www.51qsb.cn/article/dvjhqe.html

(0)
打赏微信扫一扫微信扫一扫QQ扫一扫QQ扫一扫
上一篇2023-07-22
下一篇2023-07-22

你可能还想知道

发表回复

登录后才能评论