Vm-velocity template-related ~

Source: Internet
Author: User

1.Velocity is a Java-based template engine. You can reference a Java object.
is the ability to adjust and populate page layouts and page content based on business logic, using Java objects.

I personally think that the template is to provide a shell, in what position to put what kind of data, how to put the data in order to achieve what kind of display effect.
So, the template is very similar, you just need to understand its rules of use.

2. Basic syntax:
1) "#" script statements to identify velocity, including #set, #if, #else, #end, #foreach, #end, #iinclude, #parse, #macro等;
2) "$" is used to identify an object (or to be interpreted as a variable); The first character must be a letter. can contain-_a-z0-9; can take the value of the object, the method of referencing the object;
3) "{}" is used to clearly identify the velocity variable;
4) "!" Used to force the non-existent variable to appear blank. $! return NULL character ~
I often confused is not understand $!msg and! $msg difference.
5) distinguish between single and double quotation marks:
#set ($var = "Helo")
Test "$var" returns Testhello
Test ' $var ' returns test ' $var '
You can change the default processing by setting Stringliterals.interpolate=false

3. Write an example:

# #我是注释
#* Me
Also
Comment *#
#set ($i =0)
#foreach ($info in $list)
Sequence Number: $i
#set ($i = $i + 1)
#end

I've written the same. More complex than this, it is to distinguish between the last element and other elements, plus other functions. Note here is the possible problem with "whitespace". No time bomb!

4. Have fun!

Individuals used to play smarty templates, do not like Java, there is no understanding of Java. The most recent background environment is VMS, so understand.
In fact, almost ~ ~

Personally, if it is not a traversal of the grammatical structure, it is suggested that some simple logical processing or in JS processing better. This facilitates the separation of the page and business logic, so that people maintain the code is not so painful!

Vm-velocity template-related ~

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.