本文实例讲述了PHP模板引擎Smarty内建函数。分享给大家供大家参考,具体如下:
Smarty 的内建函数:Smarty自带一些内建函数,内建函数是模板语言的一部分,用户不能创建名称和内建函数一样的自定义函数,也不能修改内建函数。
下面对 Smarty 中的内建函数进行说明,并加以实例:
实例中使用到的 Smarty 模板引擎初始化文件 init.inc.php 和主文件 index.php
init.inc.php
template_dir = ROOT_PATH.'/tpl/'; //重新指定模板目录
$_tpl->compile_dir = ROOT_PATH.'./com/'; //重新指定编译目录
$_tpl->left_delimiter = '<{'; //重新指定左定界符
$_tpl->right_delimiter = '}>'; //重新指定右定界符
?>
index.php
display('index.tpl'); //引入模板
?>
1、capture
/tpl/index.tpl
Capture
<{capture name="foo"}>
这里是 capture 函数里面的内容,默认是不显示的。
<{/capture}>
<{$smarty.capture.foo}>