#end
#end
#set( $greatlakes = ["Superior","Michigan","Huron","Erie","Ontario"] )
#set( $color = "blue" )
指令(Directives) #set( $monkey = $bill ) ## variable reference
#set( $monkey.Friend = "monica" ) ## string literal
#set( $monkey.Blame = $whitehouse.Leak ) ## property reference
#set( $monkey.Plan = $spindoctor.weave($web) ) ## method reference
#set( $monkey.Number = 123 ) ##number literal
#set( $monkey.Say = ["Not", $my, "fault"] ) ## ArrayList
#set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map
$monkey.Say.get(0)
$monkey.Map.get("bannana") $monkey.Map.banana ## same as above #set( $value = $foo + 1 ) ## Addition #set( $value = $bar - 1 ) ## Subtraction #set( $value = $foo * $bar ) ## Multiplication #set( $value = $foo / $bar ) ## Division #set( $value = $foo % $bar ) ## Remainder #set( $criteria = ["name", "address"] )
#foreach( $criterion in $criteria )
#set( $result = $query.criteria($criterion) )
#if( $result )
Query was successful
#end
#end
#set( $criteria = ["name", "address"] )
#foreach( $criterion in $criteria ) #set( $result = false ) #set( $result = $query.criteria($criterion) )
#if( $result )
Query was successful
#end
#end
#set( $directoryRoot = "www" )
#set( $templateName = "index.vm" )
#set( $template = "$directoryRoot/$templateName" )
$template
#set( $template = '$directoryRoot/$templateName’ ) #set( $size = "Big" ) #set( $name = "Ben" )
#set($clock = "${size}Tall$name" )
The clock is $clock.
#if( $foo )
Velocity!
#end
#foreach( $product in $allProducts )
#end
#foreach( $key in $allProducts.keySet() )
#end
# Default name of the loop counter
# variable reference.
directive.foreach.counter.name = velocityCount
# Default starting value of the loop
# counter variable reference.
directive.foreach.counter.initial.value = 1
First example:
#foreach( $foo in [1..5] )
$foo
#end
Second example:
#foreach( $bar in [2..-2] )
$bar
#end
Third example:
#set( $arr = [0..1] )
#foreach( $i in $arr )
$i
#end
First example:
1 2 3 4 5
Second example:
2 1 0 -1 -2
Third example:
0 1
#include( "greetings.txt", $seasonalstock )
Count down.
#set( $count = 8 )
#parse( "parsefoo.vm" )
All done with dofoo.vm!
$count
#set( $count = $count - 1 )
#if( $count > 0 )
#parse( "parsefoo.vm" )
#else
All done with parsefoo.vm!
#end
Count down.
#macro( tablerows $color $somelist )
#foreach( $something in $somelist )
| ||
$something |
#tablerows( $color $greatlakes )
Superior Michigan Huron Erie Ontario
velocimacro.library = VM_global_library.vm
velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = false
velocimacro.permissions.allow.inline.local.scope = false
velocimacro.context.localscope = false
velocimacro.library.autoreload
= false
#center( #bold("hello") ) ##invalid
#center( "#bold( 'hello' )" ) ##right
#macro( inner $foo )
inner : $foo
#end
#macro( outer $foo )
#set($bar = "outerlala")
outer : $foo
#end
#set($bar = 'calltimelala')
#outer( "#inner($bar)" )