鍍金池/ 教程/ PHP/ Smarty include
Smarty安裝
Smarty insert
Smarty 建立緩存
Smarty調(diào)試控制臺(tái)
Smarty if,elseif,else
Smarty include_php
Smarty多個(gè)緩存
Smarty方法
Smarty section,sectionelse
Smarty注釋代碼
Smarty屬性
Smarty緩沖處理函數(shù)
Smarty變量調(diào)節(jié)器
Smarty函數(shù)
Smarty組合修改器
Smarty雙引號(hào)里值的嵌入
Smarty預(yù)過(guò)濾器
Smarty foreach,foreachelse
Smarty include
Smarty Caching緩存
Smarty變量
Smarty assign用法
Smarty控制插件輸出緩沖
Smarty從配置文件讀取的變量
Smarty對(duì)象
Smarty literal
Smarty緩存集合
Smarty教程
Smarty display方法
Smarty自定義函數(shù)
Smarty配置文件
Smarty擴(kuò)展設(shè)置
Smarty數(shù)學(xué)運(yùn)算
Smarty輸出濾鏡
Smarty fetch方法

Smarty include

include

Attribute Name Type Required Default 描述
file string Yes n/a The name of the template file to include
assign string No n/a The name of the variable that the output of include will be assigned to
[var ...] [var type] No n/a variable to pass local to template

屬性 類型 是否必須 缺省值 描述
file string Yes n/a 待包含的模板文件名
assign string No n/a 該屬性指定一個(gè)變量保存待包含模板的輸出
[var ...] [var type] No n/a 傳遞給待包含模板的本地參數(shù),只在待包含模板中有效

 

Include 標(biāo)簽用于在當(dāng)前模板中包含其它模板. 當(dāng)前模板中的變量在被包含的模板中可用. 必須指定 file 屬性,該屬性指明模板資源的位置.

如果設(shè)置了 assign 屬性,該屬性對(duì)應(yīng)的變量名用于保存待包含模板的輸出,這樣待包含模板的輸出就不會(huì)直接顯示了。


Example 7-6. function include
例 7-6. include 函數(shù)演示

{include file="header.tpl"}

{* body of template goes here *}

{include file="footer.tpl"}

 

可以在屬性中傳遞參數(shù)給待包含模板. 傳遞給待包含模板的參數(shù)只在待包含模板中可見(jiàn). 如果傳遞的參數(shù)在待包含模板中有同名變量,那么該變量被傳遞的參數(shù)替代.


Example 7-7. function include passing variables
例 7-7. 帶傳遞參數(shù)的 include 函數(shù)演示

{include file="header.tpl" title="Main Menu" table_bgcolor="#c0c0c0"}

{* body of template goes here *}

{include file="footer.tpl" logo="http://my.domain.com/logo.gif"}

 

包含 $template_dir 文件夾之外的模板請(qǐng)使用 模板資源 說(shuō)明的格式.


Example 7-8. function include template resource examples
例 7-8. 使用外部模板資源的 include 函數(shù)演示

{* absolute filepath *}
{include file="/usr/local/include/templates/header.tpl"}

{* absolute filepath (same thing) *}
{include file="file:/usr/local/include/templates/header.tpl"}

{* windows absolute filepath (MUST use "file:" prefix) *}
{include file="file:C:/www/pub/templates/header.tpl"}

{* include from template resource named "db" *}
{include file="db:header.tpl"}


上一篇:Smarty注釋代碼下一篇:Smarty literal