Smarty3——内置函数
Table of Content
{$var}
{$append}
{assign}
{block}
{call}
{config_load}
{debug}
{extends}
{for}
{foreach},{foreachelse}
{function}
{if} {elseif} {else}
{include}
{include php}
{insert}
{ldelim} {rdelim}
{literal}
{nocache}
{php}
{section} {sectionelse}
{setfilter}
{strip}
{while}
Smarty自带了一些内置函数,这些函数是模板引擎的组成,会被编译到PHP代码中,以提高性能。在Smarty模板引擎可以进行简单的复制操作,只是复制而不进行输出。
{$var='Smary repeat'}
{*附加到数组中*}
{$num_count[]="add a element to array"}
{*对数组复制*}
{$num_count[0]='this is element is changed'}
{*在包含的模板进行变量复制,其包含的模板内也也可看到*}
{include file='var_config.tpl'}
{block}
{block}是
在模板上定义一块区域,以进行模板继承,子模板中{block}区块代码建辉替换父模板中对应的代码区块模板继承在编译时将编译成单独的一个编译文件。对比效果相似的
{include}
包含模板功能,模板继承的性能更高。在子父模板{block}中的内容可以通过 {$smarty.block.parent} 或 {$smarty.block.child} 进行合并
parent.tpl:
<html>
<head>
<title>{block name="title"}this id parent template and set titel messages{/block}</title>
<title>{block "title"}Default Title{/block}</title> {* short-hand *}
</head>
</html> child.tpl:
{*继承父模板*}
{extends file="parent.tpl"}
{block name="title"}
Page Title
{/block}
//让子模板内容添加在父模板 前
child.tpl
{*继承父模板*}
{extends file="parent.tpl"}
{block name="title" prepend}
child Page Title
{/block} //让子模板内容添加在父模板 后
{block name="title" append}
this is add after parent template
{/block}
//在父模块中引入子模块
parent.tpl:
<html>
<head>
<title>{block name="title"}The {$smarty.block.child} was inserted here{/block}</title>
</head>
</html> child.tpl:
{extends file="parent.tpl"}
{block name="title"}
Child Title
{/block}
//在子模块中引入父模块用
{$smarty.block.parent}
{extend}
继承父模板,在继承时必须放在第一行。
如果想要扩展父模板时只能,通过{block}来扩展,任何其他的模板内容扩展将被忽略
{include}
用于载入其他模板到当前模板,包含模板可用的变量,在当前模板也可以用。
当文件不在 $template_dir 目录下时,就可以使用{include}进行包含
可以向包含模板传递变量,只复值不输出({assgin})
可设置缓存时间(cache_lifetime)
可以设置编译得ID(compile_id)
可设置缓存的ID(cache_id)
links.tpl
<div id="box">
<h3>{$title}{/h3>
<ul>
{foreach from=$links item=l}
.. do stuff ...
</foreach}
</ul>
</div> index.php
{include 'links.tpl' title='Newest links' links=$link_array}
{* body of template goes here *}
{include 'footer.tpl' foo='bar'}
最新文章
- 解决由OpenShift自带的APC加速器造成的代码无法及时生效的问题
- Python之路 day1 用户登录多次被锁定
- mac下sublime text3安装SFTP及使用
- OsmocomBB 编译安装
- Data
- mysql 常用操作指令
- VB6 GDI+ 入门教程[1] GDI+介绍
- How to use For loop in CruiseControl.net
- Android Navigation Drawer,自定义ActionBar(标题居中)
- 加载网络映射盘中的assembly失败的处理办法
- strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏
- delphi SysErrorMessage 函数和系统错误信息表 good
- C++ try catch 捕获空指针异常,数组越界异常
- Flex在使用无线电的button切换直方图横坐标和叙述性说明
- Java8 Stream代码详解+BenchMark测试
- Laravel的unique和exists验证规则的优化
- RChain的Casper共识算法
- 【java】java三种技术架构
- ELK 处理 Percona 审计日志(填坑)
- Linux相关代码