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'}
Smarty3——内置函数的更多相关文章
- 8. Smarty3:模版中的内置函数
smarty3中对内置函数的修改比較大,加入了很多新的功能:变量声明.表达式,流程控制,函数.数组等.可是建议不要在模版中去使用过于复杂的逻辑,而是要尽量将一些程序设计逻辑写到PHP中,并在模版中採用 ...
- Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数
11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...
- Oracle内置函数:时间函数,转换函数,字符串函数,数值函数,替换函数
dual单行单列的隐藏表,看不见 但是可以用,经常用来调内置函数.不用新建表 时间函数 sysdate 系统当前时间 add_months 作用:对日期的月份进行加减 写法:add_months(日期 ...
- python内置函数
python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...
- DAY5 python内置函数+验证码实例
内置函数 用验证码作为实例 字符串和字节的转换 字符串到字节 字节到字符串
- python之常用内置函数
python内置函数,可以通过python的帮助文档 Build-in Functions,在终端交互下可以通过命令查看 >>> dir("__builtins__&quo ...
- freemarker内置函数和用法
原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...
- set、def、lambda、内置函数、文件操作
set : 无序,不重复,可以嵌套 .add (添加元素) .update(接收可迭代对象)---等于批量 添加 .diffrents()两个集合不同差 .sysmmetric difference( ...
- SQL Server 内置函数、临时对象、流程控制
SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...
随机推荐
- 区分/不区分大小写的比较,查找字符串在另一字符串中的位置,字符串开头是否包括另一字符串 hasPrefix
NSString *str; // 使用stringWithFormat生成一格式化字符串 str = [NSString stringWithFormat:@"This is %@&quo ...
- LeetCode Max Stack
原题链接在这里:https://leetcode.com/problems/max-stack/description/ 题目: Design a max stack that supports pu ...
- 【spring源码学习】spring的IOC容器在初始化bean过程
[一]初始化IOC的bean的时候Spring会执行的一些回调方法 (1)spring bean创建的前置处理 =>ApplicationContextAwareProcessor 在创建bea ...
- 记一次愚蠢的gradle操作
今晚把工作移植到mac平台,在用gradle命令 exec ./gradlew --parallel --info assembleDebug 打包apk时卡住,gradle一直处于下载状态,过了几分 ...
- django国际化总结
转:http://blog.csdn.net/ybdesire/article/details/46806739
- 7天学会HTML--HTML综述
一周学会HTML 1.HTML是什么? HTML 指的是超文本标记语言 (Hyper Text Markup Language) 2.HTML发展历程 HTML版本从1.0到4.0不断升级,其版本的规 ...
- #51单片机#超声波测距(HC-SR04)的使用方法
#51单片机#超声波测距(HC-SR04)的使用方法
- SVN报错:sqlite[S5]:database is locked
昨天下午修改几个冲突的jar包后提交svn后报错,接下来svn操作就失灵了,无论是clean up还是revert还是release lock都无济于事.解决办法: 首先下载sqlite3,我的是64 ...
- 完整的qt安装教程
大家可能认为qt收费了 其实不是 大家直接点击 这个 Community 这里的下载 Download 然后呢 就跳转到这个界面 点击 Qt Offline Installer 就会跳到这个地方 滑下 ...
- windows下通过.bat运行java程序
在windows下运行Java项目,单独的jar可以使用,java -jar xxx.jar 运行,如果是一个zip包,里面包含了class文件和所依赖的jar的时候,可以使用 (也可以以看看这里): ...