Home >Backend Development >PHP Tutorial >Detailed explanation of thinkphp's commonly used built-in tag include

Detailed explanation of thinkphp's commonly used built-in tag include

PHP中文网
PHP中文网Original
2017-03-30 16:07:572456browse

Using ordinary tags for variable output is enough, but other controls and loops must be completed and judgment function, you need to use the tag library function of the template engine . All tags in the system built-in tag library can be used directly without introducing the tag library.

XML tags have two types, including closed tags. Tags and open tags. Whether a tag is a closed tag or an open tag is determined when it is defined. It cannot be mixed. For example:

Closed tag:

<include file="read" />

Open tag:

<gt name="name" value="5">value</gt>

Built-in support The list of tags and

attributes is as follows:

tag name

function

contains attributes

include

include external templates File (closed)

file

import

import resource file (closed include js css load alias)

file,href,type,value ,basepath

volist

looparraydata output

name,id,offset,length,key,mod

foreach

Array or object traversaloutput

name,item,key

for

For loop data output

name,from,to,before,step

switch

branch judgment output

name

case

Branch judgment output (must be used with switch)

value, break

default

default output (closed must be used with switch)

None

compare

Compare output (including aliases such as eq neq lt gt egt elt heq nheq)

name,value,type

range

Range judgment output (including in notin between notbetween aliases)

name,value,type

present

Determine whether a value has been assigned

name

notpresent

Determine whether a value has not yet been assigned

name

empty

Determine whether the data is empty

name

notempty

Determine whether the data is not empty

name

defined

Determine whether the constant is defined

name

notdefined

Determine whether the constant is undefined

name

define

Constant definition (closed)

name,value

assign

Variable assignment (closed )

name,value

if

conditional judgmentoutput

condition

elseif

Conditional judgment output (closed must be used with the if tag)

condition

else

condition is not established output (closed can be used for other Tags)

none

php

using php code

none

1.include

You can use the Include tag to include external The template file is used as follows:

include tag (including external template file)

closed

closed tag

Properties

file (required): template file to be included, supports variables

示例:

1、 使用完整文件名包含

格式:

<include file="完整模板文件名" />

例如:

<include file="./Tpl/default/Public/header.html" />

这种情况下,模板文件名必须包含后缀。使用完整文件名包含的时候,特别要注意文件包含指的是服务器端包含,而不是包含一个URL地址,也就是说file参数的写法是服务器端的路径,如果使用相对路径的话,是基于项目的入口文件位置。

2、包含当前模块的其他操作模板文件

格式:

<include file="操作名" />

例如 导入当前模块下面的read操作模版:

<include file="read" />

操作模板无需带后缀。

3、 包含其他模块的操作模板

格式:

<include file="模块名:操作名" />

例如,包含Public模块的header操作模版:

<include file="Public:header" />

4、包含其他模板主题的模块操作模板

格式:

<include file="主题名:模块名:操作名" />

例如,包含blue主题的User模块的read操作模版:

<include file="blue:User:read" />

5、 用变量控制要导入的模版

格式:

<include file="$变量名" />

例如

<include file="$tplName" />

给$tplName赋不同的值就可以包含不同的模板文件,变量的值的用法和上面的用法相同。

无论你使用什么方式包含外部模板,Include标签支持在包含文件的同时传入参数,例如,下面的例子我们在包含header模板的时候传入了title和keywords变量:

<include file="header" title="ThinkPHP框架"keywords="开源WEB开发框架"/>

就可以在包含的header.html文件里面使用var1和var2变量,方法

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>[title]</title>
<meta name="keywords" content="[keywords]" />
</head>

注意:由于模板解析的特点,从入口模板开始解析,如果外部模板有所更改,模板引擎并不会重新编译模板,除非在调试模式下或者缓存已经过期。如果部署模式下修改了包含的外部模板文件后,需要把模块的缓存目录清空,否则无法生效。

 

 以上就是thinkphp常用内置标签include的详解的内容,更多相关内容请关注PHP中文网(www.php.cn)!

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn