傳送門:http://document.thinkphp.cn/manual_3_2.html#include
使用模版表達式
模版表達式的定義規則為:模塊@主題/控制器/操作
例如:
<include file="Public/header" /> // 包含頭部模版header <include file="Public/menu" /> // 包含菜單模版menu <include file="Blue/Public/menu" /> // 包含blue主題下面的menu模版
為了兼容3.1的寫法,也可以支持:
<include file="Public:header" /> <include file="Public:menu" /> <include file="Blue:Public:menu" />
可以一次包含多個模版,例如:
<include file="Public/header,Public/menu" />
使用模版文件
可以直接包含一個模版文件名(包含完整路徑),例如:
<include file="./Application/Home/View/default/Public/header.html" />
傳入參數
無論你使用什么方式包含外部模板,Include標簽支持在包含文件的同時傳入參數,例如,下面的例子我們在包含header模板的時候傳入了title和keywords變量:
<include file="Public/header" title="ThinkPHP框架" keywords="開源WEB開發框架" />
就可以在包含的header.html文件里面使用title和keywords變量,如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>[title]</title> <meta name="keywords" content="[keywords]" /> </head>