smarty 模板 学习

 

  Smarty的配置


include_once("Smarty/Smarty.class.php"); //包含smarty类文件 $smarty = new Smarty(); //建立smarty实例对象$smarty $smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量 $smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存 $smarty->template_dir = "./templates"; //设置模板目录 $smarty->compile_dir = "./templates_c"; //设置编译目录 $smarty->cache_dir = "./smarty_cache"; //缓存文件夹 //---------------------------------------------------- //左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突 //---------------------------------------------------- $smarty->left_delimiter = "{"; $smarty->right_delimiter = "}";

 

 

PHP模板引擎Smarty的变量操作符 (20个常用变量符)

 

 

capitalize [首字母大写 CASE: $name|capitalize  ] 

count_characters [计算字符数 CASE: $name|count_characters]
cat [连接字符串 CASE: $name|cat:"PHP"]
count_paragraphs [计算段落数 CASE: $name|count_paragraphs 段落后面加一回车算一段落]
count_sentences [计算句数 CASE: $name|count_sentences 句子后面加.就是算一段]
count_words [计算词数 CASE: $name|count_words]
date_format [时间格式 CASE: $name|date_format:'%Y-%m-%d' or $smarty.now|date_format:'%Y-%m-%d' ]              PHP页:$smarty-> assign("name",strtotime('-0'));    

default [默认 CASE: $name|default:"没有时间"]
escape [转码 html,htmlall,url CASE: $name|escape or $name|escape:"url" 这个是将URL转换成16进制 ]
indent[缩进 CASE: $name|indent:10.'$nbsp;' 首缩进10个空格]
lower[小写 CASE: $name|lower]
nl2br[换行符替换成<br /> CASE: $name|nl2br]
regex_replace[正则替换 CASE: $name|count_characters]
replace[替换 CASE: $name|replace:"is":"**"]
spacify[插空 CASE: $name|spacify: ]
string_format[字符串格式化 CASE: $name|count_characters]
strip[去除(多余空格) CASE: $name|strip:'' or $name|strip:'__']
strip_tags[去除html标签 CASE: $name|strip_tags]
truncate[截取 CASE: $name|truncate or $name|truncate:10.'...']
upper[大写 CASE: $name|upper]
wordwrap[行宽约束 CASE: $name|wordwrap:10:'<br>' 控制行宽度]

 

 

 

 

posted @ 2012-07-12 14:40  网络爱上点击  阅读(349)  评论(0编辑  收藏  举报