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——内置函数的更多相关文章

  1. 8. Smarty3:模版中的内置函数

    smarty3中对内置函数的修改比較大,加入了很多新的功能:变量声明.表达式,流程控制,函数.数组等.可是建议不要在模版中去使用过于复杂的逻辑,而是要尽量将一些程序设计逻辑写到PHP中,并在模版中採用 ...

  2. Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数

    11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...

  3. Oracle内置函数:时间函数,转换函数,字符串函数,数值函数,替换函数

    dual单行单列的隐藏表,看不见 但是可以用,经常用来调内置函数.不用新建表 时间函数 sysdate 系统当前时间 add_months 作用:对日期的月份进行加减 写法:add_months(日期 ...

  4. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  5. DAY5 python内置函数+验证码实例

    内置函数 用验证码作为实例 字符串和字节的转换 字符串到字节 字节到字符串

  6. python之常用内置函数

    python内置函数,可以通过python的帮助文档 Build-in Functions,在终端交互下可以通过命令查看 >>> dir("__builtins__&quo ...

  7. freemarker内置函数和用法

    原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...

  8. set、def、lambda、内置函数、文件操作

    set : 无序,不重复,可以嵌套 .add (添加元素) .update(接收可迭代对象)---等于批量 添加 .diffrents()两个集合不同差 .sysmmetric difference( ...

  9. SQL Server 内置函数、临时对象、流程控制

    SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...

随机推荐

  1. BZOJ3632: 外太空旅行

    BZOJ1547: 周末晚会 https://lydsy.com/JudgeOnline/problem.php?id=1547 分析: 对于一个串旋转若干次会回到本身,旋转次数即是同构个数,这个东西 ...

  2. hdu 5730 Shell Necklace——多项式求逆+拆系数FFT

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5730 可以用分治FFT.但自己只写了多项式求逆. 和COGS2259几乎很像.设A(x),指数是长度,系数 ...

  3. 洛谷【P1064】金明的预算方案

    浅谈\(DP\):https://www.cnblogs.com/AKMer/p/10437525.html 题目传送门:https://www.luogu.org/problemnew/show/P ...

  4. shell查看执行过程及时间变量

    sh -xv test.sh    #加参数xv查看shell执行过程. Shell 调用系统时间变量 获取今天时期:`date +%Y%m%d` 或 `date +%F` 或date +%Y-%m- ...

  5. ITextSharp Table使用 (转)

    原文:http://www.cnblogs.com/LifelongLearning/archive/2011/05/16/2048116.html 表格是我们在制作文档时,经常使用的一个元素.对布局 ...

  6. monolog 应该是世界上最好的日志插件了

    引入 composer require monolog/monolog 官网 https://github.com/Seldaek/monolog 创建工具类 <?php /** * Creat ...

  7. Java中的intern变量的讲解

    一般我们变成很少使用到 intern这个方法,今天我就来解释一下这个方法是干什么的,做什么用的 首先请大家看一个例子: public static void main(String[] args) t ...

  8. python开发mysql:单表查询&多表查询

    一 单表查询,以下是表内容 一 having 过滤 1.1 having和where select * from emp where id > 15; 解析过程;from > where ...

  9. CDM中,创建一个或多个组合属性的唯一约束

    除主键外,有时还需要创建一个或多个组合字段的唯一约束,方法如下: 双击打开实体,在idntifier标签页中可看到默认主键的唯一约束,在其下方添加一条记录,然后双击该记录,打开约束设置窗口 在该窗口的 ...

  10. 关于Pycharm中如何注释

    主要有三种方法: ①在程序行前面加“#” ②将需要注释的代码用'''----''' 包起来,此方法类似C的注释方法 ③将需要注释的代码选住然后利用“Ctrl+/”进行注释 # test=input(' ...