from http://www.codeproject.com/Articles/8141/Ader-Template-Engine,
中文参考boke:http://www.cnblogs.com/caicaihui/archive/2008/07/07/1237756.html
Ader TemplateEngine is a .NET class library (written in C#) for generating text output from source template and input parameters.
Functions :
equals(obj1, obj2)
- invokesequals
method onobj1
withobj2
as parameter. Returns boolean value.- cint(value) - return an int of value ,same as :Convert.toInt32() in C#
- cdouble(value) -return an double data
- cdata(value)
- createtypereference(type) - reference a static type
exp: #createtypereference("System.Math").Round(3.39789)#
#createtypereference("System.Math").PI#
or
< ad:set name="MyMath" value="#createtypereference("System.Math")#" />
#MyMath.Round(3.3)#
#MyMath.PI#
notequals(
obj1, obj2)
- Returns!equals(obj1, obj2)
. Is equivalent to calling:not(equals(obj1, obj2))
.iseven(num)
- tests whether number is an even number.isodd(num)
- tests whether number is an odd number.isempty(string)
- tests whether string has 0 characters. Same asequals(string.Length, 0)
.isnotempty(string)
- tests whether string has at least 1 character.isnumber(num)
- tests whethernum
is of numeric type.toupper(string)
- convertsstring
to upper case.tolower(string)
- convertsstring
to lower case.isdefined(varname)
- tests whether variable namedvarname
is defined.ifdefined(varname, value)
- returns value ifvarname
is defined. Especially useful:#ifdefined("name", name)#
- will output value ofname
if it's defined, otherwise will output nothing.len(string)
- returns length ofstring
.tolist(collection, property, delim)
- will convertcollection
to string withdelim
as separator. If you passproperty
, the value of theproperty
will be evaluated on each element of the collection. If you omitproperty
, then the object itself will be used.- typeof(object) -returns type of object,exp:typeof("abcd234") return"string" , typeof(3) return int
-
isnull(obj)
- tests whetherobj
isnull
not(boolvalue)
- returns not (!) of boolean value.iif(booleanExpression, iftruevalue, iffalsevalue)
- same asbooleanExpression ? iftruevalue : iffalsevalue
in C#.format(object, formatstring)
- will callToString(formatstring)
onobject
.object
has to implementIFormattable
interface, otherwiseToString()
will be called.-
trim(string)
- will trimstring
object -
filter(collection, booleanproperty)
- will return new List fromcollection
for those objects whose boolean property property evaluates totrue
. -
gt(obj1, obj2)
- will returntrue
ifobj1
>obj2
. (obj1
andobj2
must implementIComparable
. All numeric types do). -
lt(obj1, obj2)
- will returntrue
ifobj1
<obj2
. (obj1
andobj2
must implementIComparable
. All numeric types do). -
compare(obj1, obj2)
- will return -1 ifobj1
<obj2
, 0 ifobj1
=obj2
, and 1 ifobj1
>obj2
. (obj1
andobj2
must implementIComparable
. All numeric types do). comparenocase(string1, string2)
- will do case insensitive comparison ofstring1
andstring2
and returntrue
if they are equal.-
or(bool1, bool2)
- will returntrue
if eitherbool1
orbool2
aretrue
. and(bool1, bool2) -will return
true
if bothbool1
andbool2
aretrue
.stripnewlines(string)
- will return all\r\n
instances and replace them with space.
Built In Tags:
-
IF
<ad:if test="#equals(cust.country, "US"))#"> You are US customer. <ad:else> You are from: #cust.country# country. </ad:if>
-
FOREACH
You can loop through collection of elements (any object that implements IEnumerable
interface) using FOREACH
tag.
<ad:foreach collection="#collection#" var="cust" index="i"> #i#: #cust.lastname#, #cust.firstname# </ad:foreach>
基于.NET的免费开源的另模板引擎---VTemplate参考Kingthy's blog http://www.cnblogs.com/kingthy/archive/2009/08/17/net-vtemplate.html