$smarty->left_lelimiter = '<{';
$smarty->right_delimiter = '}>';
<{* this a note *}>
<{$name}> <{*常规类型变量,需要调用模板内的assign函数分配值*}>
<{$contacts[row].phone}> <{*数组类型变量,需要调用模板内的assign函数分配值*}>
<body bgcolor="<{#bgcolor#}>"> <{*从配置文件中读取的变量的值并输出*}>
<{$foo + 1}> <{* 变量加1 *}>
<{$foo * $bar}> <{* 两个变量相乘 *}>
<{$foo->bar - $bar[1] * $foo->bar - 3 * 7}> <{* 复合类型变量参加运算 *}>
<{if($foo + 2 == 10)}> <{* 数学运算在程序逻辑中应用 *}>
<{"test $foo test"}> <{* 双引号中使用变量 *}>
<{"test `$foo[0]` test"}> <{* 双引号中反引号包住的数组变量 *}>
<{"test `$foo.bar` test"}> <{* 双引号中反引号包住的对象成员变量 *}>
//指定一对'名称/数值'
$smarty->assign('question','你好吗');
$smarty->assign('answer','不怎么好');
//指定包含'名称/数值'
$smarty->assign(array('question' => '你好吗','answer' => '不怎么好'));//这种方式比较少用
<?php
require 'libs/Smarty.class.php';//加载Smarty.class.php文件
define('SITE_ROOT','./tpl/');//定义一个常量
$tpl = new Smarty();
$tpl->template_dir = SITE_ROOT . 'template_dir';//存模板文件
$tpl->compile_dir = SITE_ROOT . 'compile_dir';//存编译过的模板文件
$tpl->config_dir = SITE_ROOT . 'config_dir';//存特殊配置文件
$tpl->cache_dir = SITE_ROOT . 'cache_dir';//存Smarty缓存文件
$tpl->caching = 1;//启用缓存
$tpl->cache_lifetime = 60*60*24;//缓存时间1天
$tpl->left_delimiter = '<{';//左结束符
$tpl->right_delimiter = '}>';//右结束符
<?php
require 'smarty.php';
$tpl->assign('title','title测试');
$tpl->assign('content','content测试');
$tpl->display('template.html');
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
<{$title}>
</title>
</head>
<body>
<{$content}>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有