摘要: 从字符串开始处截取某长度的字符,默认是80个,你也可以指定第二个参数作为追加在截取字符串后面的文本串。该追加字串被计算在截取长度中。默认情况下,smarty会截取到一个词的末尾。如果你想要精确的截取多少个字符,把第三个参数改为"true" 。参数位置参数类型是否必需默认描述1integerNo80截取字符的数量2stringNo...截取后追加在截取词后面的字符串3booleanNofalse是截取到词的边界(false)还是精确到字符(true)4booleanNofalse设置为FALSE将截取至字符串末尾,设置为TRUE则截取到中间。注意如果设了TRUE,则忽略字符边 阅读全文
posted @ 2012-03-08 14:08 haiwei.sun 阅读(265) 评论(0) 推荐(0) 编辑
摘要: 为变量设置一个默认值。当变量未设置或为空字符串时,将由给定的默认值替代其输出。Default需要一个参数。参数位置类型是否必须默认描述1stringNoempty这是变量为空的时候的默认输出。Example 5-9. default<?php$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');$smarty->assign('email', '');?> Where template is:{$articleTitle 阅读全文
posted @ 2012-03-08 13:40 haiwei.sun 阅读(523) 评论(0) 推荐(0) 编辑
摘要: 本调节器将格式化的日期和时间经php函数strftime()处理。Unix时间戳、mysql时间戳及由年月日组成的字符串格式的日期可以传递到smarty经php函数strtotime()解析。设计者可以使用date_format完全控制日期格式,如果传给date_format的日期为空值,但提供了第二个参数,那么将使用第二参数格式化时间。 参数位置类型是否必须默认描述1stringNo%b %e, %Y输出日期的格式。2stringNon/a输入为空时,作为默认时间。从Smarty-2.6.10开始,传递给date_format的数字值(除了mysql时间戳,见下文)总是当作unix时间戳。在 阅读全文
posted @ 2012-03-08 13:39 haiwei.sun 阅读(1626) 评论(0) 推荐(0) 编辑
摘要: 计算变量里的词数 。Example 5-7. count_words<?php$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');?> Where template is:{$articleTitle}{$articleTitle|count_words} This will output:Dealers Will Hear Car Talk at Noon.7See also count_characters, count_paragraphs and 阅读全文
posted @ 2012-03-08 13:36 haiwei.sun 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 计算变量里的字符数。参数位置类型是否必须默认描述1booleanNofalse确定是否计算空格字符。Example 5-4. count_characters<?php$smarty->assign('articleTitle', 'Cold Wave Linked to Temperatures.');?>Where template is:{$articleTitle}{$articleTitle|count_characters}{$articleTitle|count_characters:true}Will output:Cold W 阅读全文
posted @ 2012-03-08 13:31 haiwei.sun 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 将cat里的值后接到给定的变量后面。参数位置类型是否必须默认描述1stringNoempty将cat里的值连接到给定的变量后面。Example 5-3. cat<?php$smarty->assign('articleTitle', "Psychics predict world didn't end");?>index.tpl:{$articleTitle|cat:" yesterday."}OUTPUT:Psychics predict world didn't end yesterday. 阅读全文
posted @ 2012-03-08 13:28 haiwei.sun 阅读(578) 评论(0) 推荐(0) 编辑
摘要: 将变量里的所有单词首字大写。它与php的ucwords()函数类似。参数位置类型必需默认描述1BooleanNoFALSE确定带数字的单词是否需要大写例 5-2.首字大写<?php$smarty->assign('articleTitle', 'next x-men film, x3, delayed.');?> Where the template is:{$articleTitle}{$articleTitle|capitalize}{$articleTitle|capitalize:true} Will output:next x-men 阅读全文
posted @ 2012-03-08 13:26 haiwei.sun 阅读(242) 评论(0) 推荐(0) 编辑
摘要: capitalize cat count_characters count_paragraphs count_sentences count_words date_format default escape indent lower nl2br regex_replace replace spacify string_format strip strip_tags truncate upper wordwrap变量调节器作用于变量、自定义函数或字符串。变量调节器的用法是:‘|’符号右接调节器名称。变量调节器可接收附加参数影响其行为。参数位于调节器右边,并用‘:’符号分开。例 5-1.调节器的例 阅读全文
posted @ 2012-03-08 12:41 haiwei.sun 阅读(226) 评论(0) 推荐(0) 编辑
摘要: Request variables[页面请求变量] {$smarty.now} {$smarty.const} {$smarty.capture} {$smarty.config} {$smarty.section} {$smarty.template} {$smarty.current_dir} {$smarty.version} {$smarty.block.child} {$smarty.block.parent} {$smarty.ldelim}, {$smarty.rdelim}可以通过php保留变量{$smarty}访问几个环境和请求变量。列表如下。Request variable 阅读全文
posted @ 2012-03-08 12:31 haiwei.sun 阅读(504) 评论(0) 推荐(0) 编辑
摘要: 你可以选择为主要的Smarty对象作用域分配变量,createData()用来建立数据对象,createTemplate()用来建立模板对象。这些对象支持链式,在模板中可以查看所有模板本身的对象变量和所有分配给父对象链的变量。默认情况下,模板在执行$smarty->displaty(...)、$smarty->fetch(...)方法时已自动链接至Smarty对象变量范围。对于分配到单个数据或模板对象的变量,您可以完全控制哪些变量在模板中可见。这些所谓的主要Smarty对象,共有三个,分别是Smarty、模板、数据;在php程序中,为这些作用域变量赋值时,首先须将它们实例化,如$s 阅读全文
posted @ 2012-03-08 12:07 haiwei.sun 阅读(495) 评论(0) 推荐(0) 编辑
摘要: 加载配置文件后,配置文件中的变量需要用两个井号"#"包围或者是smarty的保留变量$smarty.config.来调用(下节将讲到),第二种语法在变量作为属性值嵌入至引号的时候非常有用,详细可参考双引号里值的嵌入。译注(译注:举个例子 {include file="#includefile#"} 这样#includefile#将被当作字符处理,而不表示配置文件变量,但可以这样表示 {include file="`$smarty.config.includefile`"}不要忘了加``,当然也可用{$smarty.config.inc 阅读全文
posted @ 2012-03-08 11:57 haiwei.sun 阅读(299) 评论(0) 推荐(0) 编辑
摘要: 关联数组数组下标对象调用从PHP分配的变量需在前加"$"符号(译注:同php一样)。例 4-2.分配的变量PHP code:<?php$smarty = new Smarty();$smarty->assign('firstname', 'Doug');$smarty->assign('lastname', 'Evans');$smarty->assign('meetingPlace', 'New York');$smarty->display(&# 阅读全文
posted @ 2012-03-08 11:53 haiwei.sun 阅读(410) 评论(0) 推荐(0) 编辑
摘要: Smarty有几种不同类型的变量,变量的类型取决于它的前缀符号是什么(或者被什么符号包围)。Smarty的变量可以直接被输出或者作为函数属性和调节器(modifiers)的参数,或者用于内部的条件表达式等等。如果要输出一个变量,只要用定界符将它括起来就可以。例 4-1.分配的变量{$Name}{$product.part_no} <b>{$product.description}</b>{$Contacts[row].Phone}<body bgcolor="{#bgcolor#}">一个检验是否为Smarty变量的简单方法就是执行调试控 阅读全文
posted @ 2012-03-08 11:47 haiwei.sun 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 有时,忽略Smarty对某些语句段的解析很有必要。一种典型的情况是嵌入到模板中的javascript或Css代码。原因在于这些语言使用与Smarty默认定界符‘{’和‘}’一样的符号。一个避免出现这种情况的好习惯是把你的javascript/css代码分离出来保存成一个独立文件,再用html方法链接到模版中。这样做也有利于浏览器缓存脚本。如果你想把Smarty变量、方法嵌入到javascript/css,请看下面的运用。在Smarty模版,如果‘{’和‘}’大括号里包含有空格那么整个{}内容会被忽略,你可以设置Smarty类变量$auto_literal=false来取消这种规则。Exampl 阅读全文
posted @ 2012-03-08 11:43 haiwei.sun 阅读(953) 评论(0) 推荐(0) 编辑
摘要: 数学运算可以直接作用到变量值。例 3-7.数学运算的例子 {$foo+1}{$foo*$bar}{* some more complicated examples *} {* 一些更复杂的示例 *}{$foo->bar-$bar[1]*$baz->foo->bar()-3*7}{if ($foo+$bar.test%$baz*134232+10+$b+10)}{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}{assign var="foo" value="`$foo+$b 阅读全文
posted @ 2012-03-08 11:38 haiwei.sun 阅读(334) 评论(0) 推荐(0) 编辑
摘要: Smarty will recognize assigned variables embedded in "double quotes" so long as the variable name contains only numbers, letters and under_scores. See naming [http://php.net/language.variables] for more detail.With any other characters, for example a .period or $object>reference, then t 阅读全文
posted @ 2012-03-08 11:35 haiwei.sun 阅读(440) 评论(0) 推荐(0) 编辑
摘要: 大多数函数都带有自己的属性以便于明确说明或者修改他们的行为,smarty函数的属性很像HTML中的属性。静态数值不需要加引号,但是字符串建议使用引号。可以使用普通smarty变量,也可以使用带调节器的变量作为属性值,它们也不用加引号。你甚至可以使用php函数返回值和复杂表达式作为属性值。一些属性用到了布尔值(true或false),它们表明为真或为假。如果没有为这些属性赋布尔值,那么默认使用true为其值。译注函数、调节器的属性实际为函数的参数。例 3-3.函数属性语法 {include file="header.tpl"}{include file="heade 阅读全文
posted @ 2012-03-08 11:30 haiwei.sun 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 每一个smarty标签输出一个变量或者调用某种函数。在定界符内函数(一般定界符‘{}’包住)和其属性(同样在定界符内)将被处理和输出。例如: {funcname attr1="val" attr2="val"}.例 3-3.函数语法 {config_load file="colors.conf"}{include file="header.tpl"}{if $highlight_name} Welcome, <font color="{#fontColor#}">{$name}!&l 阅读全文
posted @ 2012-03-08 11:22 haiwei.sun 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 模板变量用美元符号$开始,可以包含数字、字母和下划线,这与php变量很像。你可以引用数组的数字或非数字索引,当然也可以引用对象属性和方法。译注译注:按照说明像$abc、$abc123、$abc_123、$abc[1]、$abc['a']、$abc->a、$abc->a()这些模板变量都是有效的。配置文件变量是一个不用美元符号$,而是用#号包围着变量(#hashmarks#),或者是一个$smarty.config形式的变量。Example 3-2. 变量{* 演示server变量"SERVER_NAME"($_SERVER['SERVER 阅读全文
posted @ 2012-03-08 11:19 haiwei.sun 阅读(779) 评论(0) 推荐(0) 编辑
摘要: 模板注释被*星号包围,而两边的星号又被定界符包围,例如 {* this is a comment *} 。smarty注释不会在模板文件的最后输出中出现,这与<!-- HTML 注释-->不同(译注:html注释在页面源码中可见,而smarty注释则不能)。这点非常有用,试想,注释只存在于模板里面,而在输出的页面中谁也看不见:)。eg:{* another single line smarty comment *} 阅读全文
posted @ 2012-03-08 11:05 haiwei.sun 阅读(326) 评论(0) 推荐(0) 编辑
返回顶部