1#macro (Formatincreasedata$increase)2 #if (${product.onlinestatusflag} = = ' 0 ')3--4 #elseif (! $increase | | $increase = = "") 6 #else 7 #if ($increase >= 0 ) 8 #set ($color = "Increase-number" ) 9 #elseif ($increase < 010 #set ($color = "Is-decrease" ) 11 #end 12 <span Span style= "color: #0000ff;" >class= "$! {color} ' >${numberutils.percentageformat ($!{ Increase})}</span>13 #end 14 #end
1#macro (Rendertheme$themeList)2 #if ($themeList. Size () >0)3#foreach ($renqi in $themeList)4 #set ($themeSelected = "")5 #set ($closeIcon = "")6 #if ($!{ Fundgroupid} = =$renqi. ID) 7 #set ($themeSelected = "cur" ) 8 #set ($closeIcon = "<span class= ' Closeicon ' ></span>" ) 9 #end 10 <li> <a class= "Theme-name $!{ themeselected} "data-sk=" All-remen "title=" $! {Renqi.memo} "href=" "data-identity=" Fundgroupid "data-val=" $! {renqi.id} "><span class=" ">$!{ Renqi.groupname}</span>11 $! {Closeicon} 12 </a >13 </li> 14 #end 15 #end
The macro in velocity can be understood as the definition of a function , and when used, it is necessary to consider the scope of the macro.
1. Variables in the outer macro can be accessed in a macro in memory
2, the inner layer of the macro variable if the variable name in conflict with the outer, if there is a pass value to take the value passed in, if there is no value, then take the upper level of the macro value!
In the example above, the name is defined as:
Functions of the Rendertheme
The method is called:
#renderTheme ($fundGroup. renqilist)2 #renderTheme ($fundGroup. zhutilist)
So, Velocity's macro maximizes the function of velocity as a synchronous template engine!
Velocity (5)--#macro directive