1. variable definition
Because it is a weak type language, you do not need to define the type of the variable. The Compiler automatically determines Based on the Value assignment type. The defined keyword is set.
Add #. $ must be added before the variable name. The combination of the variable name and value must be placed in parentheses. You do not need to use a semicolon to conclude the sentence. For example:
# Set ($ maxvalue = 5)
# Set ($ name = "Bob ")
Also
An array can be defined in the following format:
# Set ($ arrayname = ["element1", "element2",...])
Example
For example: # Set ($ members = ["Mary", "Rose", "Mr Black"])
2. Notes
Single Row note
The format is as follows:
# Set ($ name = "Mike") # This is a comment: define the name as Mike
Comment on multiple rows in the following format:
# Set ($ name = "Mike ")
#*
This
Is a multi-line comment: the definition name is Mike,
If it is defined as another one, it does not meet user habits!
*#
3. Process Control
Support
The following process controls are supported: # If... # else... # End (logical judgment statement) and # foreach (... in
...)... # End (loop statement), which can be nested. Example: If
# Set ($ name = "Mary ")
# Set ($ sex = "female ")
# Set ($ age = 20)
# Set ($ coutry = "America ")
# If ($ name = "Mary ")
Hello Mary!
# End
# If ($ sex = "male ")
You are a boy!
# Else
You are a girl!
# End
# If ($ age <12)
You are too young!
# Elseif ($ age> 12 & $ age <18)
You are not
Adult!
# Else
You are an adult!
# End
# If ($ country! = "China ")
# If ($ Country = "amemica ")
You are from America!
# End
# Else
# If ($ city = "Beijing ")
You are from Beijing!
# Else
You
Are not from Beijing!
# End
# End
Example: foreach
# Set ($ members = ["Mary", "Rose", "Mike"])
# Foreach ($ member in
$ Members)
$ Member
# End
Another
In addition, the foreach loop not only displays the array content, but also the content of objects such as vector, list, And iterator in Java,
4. # foreach () # End is used for loop output and exit
# Foreach ($ key in
$ Allproducts. keyset ())
<Li> key: $ key-> value:
$ Allproducts. Get ($ key) </LI>
# If ($ votecitycount> 5) # break # End
# End
5.
# Include: Used to include some resource files. Of course, include does not parse resource files.
# Include ("one.txt ")
# Parse, used for parsing and including corresponding resource files
# Parse ("me. VM"), which shares the corresponding context with the main file
# Stop: Used to stop parsing and return results. It is mainly used for debugging.
6. Velocity # macro is quite powerful.
# Macro, similar to macro definition, is used to customize the corresponding tag.
A macro is defined as follows, which is used to output the list in the table.
# Macro (tablerows $ color $ somelist)
# Foreach ($ something in $ somelist)
<Tr> <TD
Bgcolor = $ color> $ something </TD> </tr>
# End
# End
In the template, you only need to use # tablerows ($ color $ somelist) to replace the Code:
# Set ($ greatlakes = ["superior", "Michigan", "Huron", "Erie", "Ontario"])
# Set ($ color = "blue ")
<Table>
# Tablerows ($ color
$ Greatlakes)
</Table>
# Macro
The built-in syntax is supported, so the template definition becomes more flexible and simple.