smarty 模板包含

来源:互联网 发布:js array.join 编辑:程序博客网 时间:2024/05/09 14:44

Example 7-6. function include
Smarty手册范例 7-6. 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
Smarty手册范例 7-7. 带传递参数的 include 函数演示

{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.

包含 $template_dir 文件夹之外的模板请使用 模板资源 说明的格式.

Example 7-8. function include template resource examples
Smarty手册范例 7-8. 使用外部模板资源的 include 函数演示

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


原创粉丝点击