Introduction to the basic syntax of velocity scripts

Source: Internet
Author: User
Velocity is a Java-based template engine, which allows anyone to simply use the template language to reference CodeDefined Object. As a relatively complete template engine, velocity has powerful functions, but it also increases application complexity. The basic syntax of the simple velocity script is as follows: 1. "#" is the script statement used to identify the velocity, including # Set, # If, # else, # End, # foreach, # End, # iinclude, # parse, # macro, etc;
For example:
# If ($ info. IMGs)

# Else

# End

2. "$" is used to identify an object (or as a variable );
For example, $ I, $ MSG, $ tagutil. Options (...), etc.

3. "{}" is used to clearly identify the velocity variable;
For example, there is a $ someonename in the page. In this case, velocity uses someonename as the variable name. ProgramTo display the name character next to the someone variable, the above label should be changed to $ {someone} Name.

4 ,"! "Is used to forcibly display non-existent variables as blank.
For example, if the page contains $ MSG, the value of MSG is displayed if the MSG object has a value. If the MSG object does not exist, the $ MSG character is displayed on the page. This is not expected. In order to display a non-existent variable or an object whose value is null as a blank space, you only need to add a "!" before the variable name. .
Example: $! MSG

 

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.