ecmall解析语法与机制

上传人:繁星 文档编号:40614275 上传时间:2018-05-26 格式:DOC 页数:12 大小:91.50KB
返回 下载 相关 举报
ecmall解析语法与机制_第1页
第1页 / 共12页
ecmall解析语法与机制_第2页
第2页 / 共12页
ecmall解析语法与机制_第3页
第3页 / 共12页
ecmall解析语法与机制_第4页
第4页 / 共12页
ecmall解析语法与机制_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《ecmall解析语法与机制》由会员分享,可在线阅读,更多相关《ecmall解析语法与机制(12页珍藏版)》请在金锄头文库上搜索。

1、ECMall 模板解析语法与机制在 ECMall 模板中,用”“开头,以”结尾就构成一个标签单元,”“紧接着的单词就是标签名。在标签单元中单词前含”$”(美元符)的为变量名。资资源引用源引用res 标签标签功能:返回当前模板当前风格目录的 url 路径实例:res file=css/ecmall.css这个标签在模板编译后将变成 http:/商城域名/themes/default/styles/default,注意末尾没有”/”,返回结果会随后台设置的主题变化lib 标签标签功能:返回 javascript 库的 url 路径实例:lib file=ecmall.js这个标签在模板编译后将变成

2、 http:/商城域名/includes/libraries/javascript,注意末尾没有”/”,返回结果不会随后台设置的主题变化url 标签标签功能:url 解析器,可根据后台伪静态状态返回相应 url 等。说明:如果一个链接的目标页面需要伪静态功能,请使用该 url 标签,只有当后台开启伪静态并在.htaccess 文件为目标页面设置了伪静态规则时 url 标签才能解析为静态 url 地址。实例:url app=goods /普通变量$this-assign(user, array(name = Tom,age = 28); /数组变量$this-display(index.html

3、);在 themes/mall/default/index.html 中显示变量Hello,$name,your age are $user.age!在模板中赋值变量。assign 标签,例在 themes/mall/default/index.html 中赋值变量assign var=“name“ value=“Tom“ Hello,$firstname!3.模板上使用模板上使用语语言言项项说明:为了满足多语言需求,ECMall 采用了语言包机制,除挂件外,在模板、js 文件中均使用语言项代替直接显示语言文字。语言文件:语言文件位于商城根目录下的 languages 目录下,为当前语言建了一

4、个目录,如果您用的是 sc-gbk 版本,则会有 sc-gbk 目录,进去之后就能看到属于前台控制器的全部语言文件了。除 common.lang.php 属于所有 app 外,每一个语言文件都只属于一个 app(ECMall 中称为控制器)。语言文件属于某个控制器而不属于某个模板,同一个模板如果被不同控制器调用将使用不同语言文件进行语言解析。在默认控制器对应的语言文件 default.lang.php 添加语言项”test”:热门搜索,. .best_recommended = 精品推荐,test = 测试语言项); ?在 index.html 模板中显示语言项”test”$lang.test

5、模板中还支持数组形式语言项,在默认控制器对应的语言文件 default.lang.php添加语言项”test_array”热门搜索,. .best_recommended = 精品推荐,test_array = array(key1 = 测试数组语言项,key2 = 太好了), ); ?在 index.html 模板中显示语言项”test”$lang.test_array.key14. 变变量量调节调节器器* escape功能:提供各种编码功能。参数:可选参数 html、url、quotes、input、editor,缺省为 html html:分别替换变量中的如下字符 $this-displ

6、ay(index.tpl);模板$goods_name $goods_name|escape $goods_name|escape:“html“$goods_name|escape:“url“ $goods_name|escape:“quotes“ $goods_name|escape:“input“ $goods_name|escape:“editor“输出结果为Loreal/欧莱雅“清润全日保湿乳霜“50mlLoreal/欧莱雅“清润全日保湿乳霜“50mlLoreal/欧莱雅“清润全日保湿乳霜“50mlL%27oreal%2F%E6%AC%A7%E8%8E%B1%E9%9B%85%22%E

7、6%B8%85%E6% B6%A6%E5%85%A8%E6%97%A5%E4%BF %9D%E6%B9%BF%E4%B9%B3%E9%9C%9C%2250ml%3Cbr+%2F%3E%3Cscri pt%3ELoreal/欧莱雅“清润全日保湿乳霜“50mlLoreal/欧莱雅“清润全日保湿乳霜“50mlLoreal/欧莱雅“清润全日保湿乳霜“50ml* nl2br功能:将换行符替换成view sourceprint?1 $var|nl2br * default功能:为变量设置一个默认值,当变量为空或者未分配的时候,将由默认值替代输出view sourceprint?1 $var|default

8、:“no title“ * truncate功能:字符串截取。从字符串开始处截取某长度的字符。默认会在末尾追加省略号。view sourceprint?1 $content|truncate:20 * strip_tags功能:去除标签,包括在之间的任何内容。view sourceprint?1 assign var=“content“ value=“文章内容“ 2 $content|strip_tags * price功能:格式化价格。view sourceprint?1 assign var=“goods_price“ value=“123456“ 2 $goods_price|price

9、 输出结果为:123,456.00* date功能:格式化本地时间和日期。格式:$var|date:format说明:变量$var 必须是格林尼治标准时间,php 中 gmtime()和模板中$smarty.now得到的都是格林尼治标准时间,参数 format 可为 simple、complete 或自定义日期格式,缺省为 simple。view sourceprint?1 $smarty.now|date 2 $smarty.now|date:complete 3 $smarty.now|date:Y-m-d H:i 输出结果为:view sourceprint?1 2010-12-01 2

10、 2010-12-01 22:49:46 3 2010-12-01 22:49 * modifier功能:调用 php 自定义函数。格式:$var|modifier:user_func流程控制标签1. 条件判断(if,elseif,else)模板中的 if 语句和 php 中的 if 语句一样灵活易用,并增加了几个特性以适宜模板引擎. if 必须于 /if 成对出现. 可以使用 else 和 elseif 子句. 可以使用以下条件修饰词:eq、ne/neq、gt、lt、lte/le、gte/ge、mod、not、=、!=、=、%、!使用这些修饰词时必须和变量或常量用空格格开.多个条件之间用 a

11、nd、or、 模板代码:view sourceprint?1 * 键就是数组的下标,请参看关于数组的解释 * 2 3 foreach name=outer item=contact from=$contacts 4 foreach key=key item=item from=$contact 5 $key: $item 6 /foreach 7 /foreach 输出结果为:view sourceprint?1 phone: 1 2 fax: 2 3 cell: 3 4 phone: 555-4444 5 fax: 555-3333 6 cell: 760-1234view sourcepr

12、int?1 * 最后一行不显示标签 * 2 3 foreach name=outer item=contact from=$contacts name=my_name 4 foreach key=key item=item from=$contact 5 $key: $itemif !smarty.foreach.my_name.last/if 6 /foreach 7 /foreach 显示标签* cyclecycle 用于轮转使用一组值。该特性使得在表格中交替输出颜色或轮转使用数组中的值变得很容易。格式:cycle values=“val1,val2,val3.“view sourcepr

13、int?1 foreach from=$data_list item=data 2 3 $data 4 5 /foreach 输出结果为:view sourceprint?1 2 1 3 4 5 2 6 7 8 3 9 * html_options自定义函数 html_options 根据给定的数据创建选项组. 该函数可以指定哪些元素被选定. 要么必须指定 values 和 ouput 属性,要么指定 options 替代。view sourceprint?1 $this-assign(cust_ids, array(1000,1001,1002,1003); 2 $this-assign(c

14、ust_names, array(Joe Schmoe,Jack Smith,Jane Johnson,Carlie Brown); 3 $this-assign(customer_id, 1001); 模板代码:view sourceprint?1 2 html_options values=$cust_ids selected=$customer_id output=$cust_names 3 view sourceprint?1 $this-assign(cust_options, array( 2 1001 = Joe Schmoe, 3 1002 = Jack Smith, 4 10

15、03 = Jane Johnson, 5 1004 = Charlie Brown); 6 $this-assign(customer_id, 1001); 模板代码:view sourceprint?1 2 html_options options=$cust_options selected=$customer_id 3 实例 1 和实例 2 输出结果均为:view sourceprint?1 2 Joe Schmoe 3 Jack Smith 4 Jane Johnson 5 Carlie Brown 6 * html_radios自定义函数 html_radios 根据给定的数据创建单选按钮组。该函数可以指定哪个元素被选定。要么必须指定 values 和 ouput 属性,要么指定 options 替代。与html_options 不同的是 html_radios 有一个 checked 属性。* html_checkbox自定义函数 htm

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 总结/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号