文章搜索:
·PHP技术论坛 ·PHP源码下载 ·招聘求职
好记性不如常笔记,学好PHP,需要养成做笔记的好习惯,马上申请我的在线笔记,终生免费>>
   你的位置: PHP教程部落 > PHP Smarty专题 > include

include

include

属性名称TypeRequiredDefaultDescription
filestringYesn/aThe name of the template file to include
assignstringNon/aThe name of the variable that the output of include will be assigned to
[var ...][var type]Non/avariable to pass local to template

Include tags are used for including other templates in the current template. Any variables available in the current template are also available within the included template. The include tag must have the attribute "file", which contains the template resource path.

You can optionally pass the assign attribute, which will specify a template variable name that the output of include will be assigned to instead of displayed.

Example 7-6. function include

{include file="header.tpl"}



{* body of template goes here *}



{include file="footer.tpl"}

You can also pass variables to included templates as attributes. Any variables explicitly passed to an included template as attributes are only available within the scope of the included file. Attribute variables override current template variables, in the case they are named alike.

Example 7-7. function include passing variables

{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"}

Use the syntax for template resources to include files outside of the $template_dir directory.

Example 7-8. function include template resource examples

{* 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"}