当前位置: 首页 > 未分类>阅读正文

smarty 在 html include

2022.7.9 朱丰华 1064 次 留下评论 1270字

内置函数include :在模板(前端视图)页面中包含其他文件

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title></title>

</head>

<body>

    {include file = 'header.html'}    {* 模板(前端视图)页面中包含外部文件 *}

</body>

</html>

使用 smarty 引入 css、和 js 文件,和直接 link 不同,使用 smarty 时如果忽略缓存则会禁止浏览器缓存,可用于忽略缓存调试,在开发者模式下比较友好。

属性:

参数名称类型必选参数默认值说明
filestringYesn/a包含载入的文件名
assignstringNon/a将包含的文件内容赋值给变量
cache_lifetimeintegerNon/a单独开启被包含模板的缓存时间
compile_idstring/integerNon/a单独设置被包含模板的编译ID
cache_idstring/integerNon/a单独设置被包含模板的缓存ID
scopestringNon/a定义被包含模板的赋值变量作用范围: ‘parent’,’root’ 或 ‘global’
[var …][var type]Non/a传递到包含模板的变量

可选标记:

nocache关闭包含模板的缓存
caching打开包含模板的缓存
inline设置成true时,在编译时把包含模板的内容也合并到当前模板的编译文件中。

包含模板将不被缓存:

{include 'sub_template.tpl' nocache}
...

引入不同路径资源的例子:

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

{* include a $variable template - eg $module = 'contacts' *}
{include file="$module.tpl"}

{* wont work as its single quotes ie no variable substitution *}
{include file='$module.tpl'}

{* include a multi $variable template - eg amber/links.view.tpl *}
{include file="$style_dir/$module.$view.tpl"}

本篇完,还有疑问?留下评论吧

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注