您的位置:首页 > 其它

AderTemplate模版引擎使用分析(二)

2008-02-01 16:02 543 查看
Ver2.1还添加了以下操作符:

is - 和调用equal方法相同. Ex: #obj1 is obj2# 会返回if obj1 equal obj2

isnot - 和调用notequal方法相同. Ex: #obj1 isnot obj2#

and - 相当于c#中的&&操作符

or - 相当于c#中的||

lt, lte, gt, gte - lt(less than,即c#中的"<"), lte(less than or equal,即c#中的"<="), gt(greater than 即c#中的">") and gte(greater than or equal,c#中的">="). 当使用数字类型操作时,必须是相同的类型.如果希望比较double和int类型,必须将int转换为double类型(使用cdouble函数).

#varOne lt 3#

#varTwo lte cdbl(3)#

#varThree gt varFour and varFive gte 5.0#

Built In Tags(内置标签???):

IF

你可以使用IF根据表达式有条件的输出文本:

<ad:if test="#booleanexpression#">

<ad:elseif test="#bool#">

<ad:else>

</ad:if>

elseif和else是可选的,当if运算返回真的时候,if代码块中包含的代码将被执行(输出);否则执行elseif运算,然后是else.

Ex:

<ad:if test="#cust.country is "CHINA"#">

You are CHINA customer.

<ad:else>

You are from: #cust.country# country.

</ad:if>

如果cust.country是CHINA的话,输出:you are CHINA customer.

FOREACH

你可以使用foreach对集合内的元素进行循环遍历.

<ad:foreach collection="#collection#" var="cust" index="i">

#i#: #cust.lastname#, #cust.firstname#

</ad:foreach>
假设customers是customer的集合:customers = Customer("Tom", "Jackson"), Customer("Mary", "Foo")

输出将是:

1. Jackson, Tom

2. Foo, Mary

在循环处理中,变量名称将被集合中的元素替换.foreach中的index属性可以省略,它被用来在循环中表示循环标志.开始于1并在每次迭代中自动增加.

FOR

你可以通过一个整数标志来进行FOR循环:

<ad:for from="1" to="10" index="i">

#i#: #customers[i].name#

</ad:for>

SET

Set标签允许设值通过其他表达式:

<ad:set name="var" value="#someexpression#" />

当Set语句执行后,你可以象使用局部变量一样使用var.当存取复杂类型的对象的时候非常有用.

以下写法:

#customers[i].address.firstname#

#customers[i].address.lastname#

#customers[i].address.address1#
可以写成:

<ad:set name="add" value="#customers[i].address#" />

#add.firstname#

#add.lastname#

#add.address1#
Custom Templates(定制模版):

你可以在模版文件中创建自己可调用的的模版.使用Template标签来做:

<ad:template name="ShowCustomer">

#customer.lastname#, #customer.firstname#

</ad:template>

<ad:showcustomer customer="#cust#" />
你可以为自定义的模版添加任何属性,然后就可以在模版中使用他们.自定义模版也可以使用在它之外定义的任何变量,当调用自定义模版的时候必须在最后加上/或者加关闭标签

Ex:

<ad:showcustomer />

OR

<ad:showcustomer></ad:showcustomer>

Ex:

<ad:template name="bold">

<b>#innerText#</b>

</ad:template>

<ad:bold>#cust.lastname#, #cust.firstname#</ad:bold>

输出: <b>Jackson, Tom</b> (if customer is Tom Jackson)

模版可以嵌套使用:

<ad:template name="italic">#innerText#</ad:template>

<ad:bold><ad:italic>This will be bold and italic</ad:italic></ad:bold>

模版可以嵌套定义:

<ad:template name="doit">

<ad:template name="colorme">

<font color=#color#>#innerText#</font>

</ad:template>

<ad:colorme color="blue">colorize me</ad:colorme>

</ad:template>
嵌套定义的模版只能在按照定义顺序在父模版中使用.

也可以在程序中定义模版:

TemplateManager mngr = mngr.AddTemplate(Template.FromString("bold", "<b>#innerText#</b>"));
现在bold模版可以在以后使用了.

(未完,等续)

AderTemplate官方网站:http://www.adersoftware.com

AderTemplate dll下载地址:http://www.aspxon.com/ShowSoft/15.aspx

AderTemplate源码下载地址(含有演示):AderTemplate(dll)模版引擎(c#源码)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: