Velocity (5)--#macro directive

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.