Nvelocity macro usage

Source: Internet
Author: User

1. nvelocity Parameters
Example:
1. Establish a macro
# Macro (test $ range $ arraylist)
...
# End
2. macro call
# Test ([-9,-1] ["favorite", "color"])
In the preceding example, you only need a # macro command that provides the name for each parameter to be passed. These parameters are separated by spaces. In the above example, # macro (test $ range $ arraylist) "test" is a macro name, and $ range $ arraylist is a parameter. Use "#" + macro name (parameter 1 parameter 2...) to call the macro.


2. nvelocity recursive call

Nesting. The simplest case is to use macro to call another macro in nvelocity.CodeThe most frequently used one in development. Recursion is a special type of nesting. It calls itself in macro in nvelocity, but this situation is not very common.
 
# Macro (recurs $ depth)
Enter the $ depth layer <br/>

# Set ($ depth = $ depth-1)

# If ($ depth> 0)

# Recurs ($ depth)

# End

# Set ($ depth = $ depth + 1)

Enter the $ depth layer <br/>

# End
# Recurs (3)
 
Execution result:
Go to Layer 3
Go to Layer 3
Go to Layer 3
Go to Layer 3
Go to Layer 3
Go to Layer 3
Note: During recursive calls, do not pass the attribute of an objectParametersRecursive call. In the preceding example, if $ depth is an object, use # recurs ($ depth. attribute), the template output is often faulty and cannot be found. Record it here and forget not to make such an error. The reason is that I think it is because of the object type. I often cannot recognize the object type when calling it (I can only understand it like this for the time being, but I have not studied it in depth ).

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.