Smarty模板中变量修饰格式: {$var|方法1:参数1:参数2…|方法2…}
来源:互联网 发布:表扬淘宝客服的话语 编辑:程序博客网 时间:2024/06/03 19:23
capitalize [首字母大写]
cat :”characters”[连接字符串]
count_characters:true/false [计算字符数]
count_paragraphs [计算段落数]
count_sentences [计算句数]
count_words [计算词数]
date_format:”%Y-%m-%d” [时间格式]
Default:”aaa” [默认]
indent[缩进]
lower[小写 ]
nl2br[换行符替换成<br />]
regex_replace[正则替换]
replace[替换]
string_format[字符串格式化]
strip[去除(多余空格)]
strip_tags[去除html标签]
truncate[截取]
upper[大写]
原文:{$str}
<p>
变量中的字符数(包括空格):{$str|count_characters:true}
使用变量修饰方法后:{$str|nl2br|upper|cat:"this is cat test"}<br>
data:{$smarty.now|date_format:"%Y-%m-%d"}Smarty 中的 if 语句和 php 中的 if 语句一样灵活易用,并增加了几个特性以适宜模板引擎.
if 必须于 /if 成对出现. 可以使用 else 和 elseif 子句.
可以使用以下条件修饰词:eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>=. 使用这些修饰词时必须和变量或常量用空格格开.
Section一般用于比较复杂的数组{section name=secname loop=$arr start=num step=num}
…
{/section}
Name是循环名称,loop为循环数组,start为循环的起始位置,step是循环步长。
<table width="500" border="1">
<tr>
<td width="187">用户名</td>
<td width="254">性别</td>
<td width="37">电话</td>
</tr>
{section name=sec1 loop=$rsarr}
<tr>
<td>{$rsarr[sec1].name}</td>
<td>{$rsarr[sec1].sex}</td>
<td>{$rsarr[sec1].tel}</td>
</tr>
{/section}
</table>
Literal 标签区域内的数据将被当作文本处理,此时模板将忽略其内部的所有字符信息. 该特性用于显示有可能包含大括号等字符信息的 javascript 脚本. 当这些信息处于 literal /literal标签中时,模板引擎将不分析它们,而直接显示.
{literal}
<script language=javascript>
<!–
function say(field) {
alert(“hello”);
}
// --> </script>
{/literal}
$template_dir
$compile_dir
$cache_dir
$config_dir
$debugging
$caching
使用缓存:
$smarty->cache_dir = "cache";
$smarty->cache_lifetime = 60 * 30;
$smarty->caching = true;
// 模板缓存
if(!$smarty->is_cached("tpl_cache.tpl")) {
// do database calls, assign vars here
}
$smarty->display("tpl_cache.tpl");
设置单个缓存会话期
$smarty->cache_dir = "cache";
$smarty->caching = 2;
// set the cache_lifetime for index.tpl to 5 minutes
$smarty->cache_lifetime = 300;
$smarty->display('index.tpl');
// set the cache_lifetime for home.tpl to 1 hour
$smarty->cache_lifetime = 3600;
$smarty->display('home.tpl');
清除缓存
$smarty->cache_dir = "cache";
$smarty->caching = true;
// clear out all cache files
$smarty->clear_all_cache();
// clear only cache for index.tpl
$smarty->clear_cache('index.tpl');
$smarty->display('index.tpl');
Fetch方法
$smarty->assign('title','第一个Smarty程序');
$smarty->assign('content','Hello,Welcome to study \'Smarty\'!');
//$smarty->output('a.html');
$output=$smarty->fetch('index.tpl');
$fp=fopen("a.html","wb");
fwrite($fp,$output);
fclose($fp);
0 0
- Smarty模板中变量修饰格式: {$var|方法1:参数1:参数2…|方法2…}
- 方法就是完成特定功能的代码块。 方法的格式: 修饰符 返回值的类型 方法名(参数类型 参数名1,参数类型 参数名2、、、、、、、、、 ){ 方法体; Return 返回值; } 赋值调用的格式:
- smarty中往insert中传参数的方法 .
- C#方法参数修饰符
- smarty模板引擎变量的传递方法
- final关键字可以用来修饰类、方法、变量、参数,不能修饰抽象类和接口
- final关键字可以用来修饰类、方法、变量、参数,不能修饰抽象类和接口
- final关键字可以用来修饰类、方法、变量、参数,不能修饰抽象类和接口
- final关键字可以用来修饰类、方法、变量、参数,不能修饰抽象类和接口
- java中final修饰方法传入参数的影响
- Java中方法用final修饰参数的作用
- Java中类,变量,方法,接口的修饰…
- smarty模板引擎的变量修饰器
- final 来修饰方法参数的原因
- Java-用final修饰方法参数
- JQuery中$.ajax()方法参数详…
- Smarty模板的2种循环方式及Smarty中变量定义
- 调试smarty模板时,查看变量的方法
- ARP地址解析协议
- 关于PHP5 Session生命周期介绍
- MySql查询结果按照指定顺序排序
- Linux 杂记
- <meta http-equiv=...> 的功能
- Smarty模板中变量修饰格式: {$var|方法1:参数1:参数2…|方法2…}
- php curl_init函数用法
- background-position属性
- warning: incompatible implicit declaration of built-in function ‘strlen’
- 2013年04月03日
- 2013年04月03日
- crontab命令的功能是在一定的时间间隔调度一些命令的执行
- 关于千千静听在win7系统下无法打开网络媒体
- QuickStart with RHOS(Red Hat OpenStack) Folsom Preview