Velocity mode

 
1
## Velocity Code Demo
2
#*
3
   based on PL/SQL mode by Peter Raganitsch, adapted to Velocity by Steve O'Hara ( http://www.pivotal-solutions.co.uk )
4
   August 2011
5
*#
6
7
#*
8
   This is a multiline comment.
9
   This is the second line
10
*#
11
12
#[[ hello steve
13
   This has invalid syntax that would normally need "poor man's escaping" like:
14
15
   #define()
16
17
   ${blah
18
]]#
19
20
#include( "disclaimer.txt" "opinion.txt" )
21
#include( $foo $bar )
22
23
#parse( "lecorbusier.vm" )
24
#parse( $foo )
25
26
#evaluate( 'string with VTL #if(true)will be displayed#end' )
27
28
#define( $hello ) Hello $who #end #set( $who = "World!") $hello ## displays Hello World!
29
30
#foreach( $customer in $customerList )
31
32
    $foreach.count $customer.Name
33
34
    #if( $foo == ${bar})
35
        it's true!
36
        #break
37
    #{else}
38
        it's not!
39
        #stop
40
    #end
41
42
    #if ($foreach.parent.hasNext)
43
        $velocityCount
44
    #end
45
#end
46
47
$someObject.getValues("this is a string split
48
        across lines")
49
50
$someObject("This plus $something in the middle").method(7567).property
51
52
#macro( tablerows $color $somelist )
53
    #foreach( $something in $somelist )
54
        <tr><td bgcolor=$color>$something</td></tr>
55
        <tr><td bgcolor=$color>$bodyContent</td></tr>
56
    #end
57
#end
58
59
#tablerows("red" ["dadsdf","dsa"])
60
#@tablerows("red" ["dadsdf","dsa"]) some body content #end
61
62
   Variable reference: #set( $monkey = $bill )
63
   String literal: #set( $monkey.Friend = 'monica' )
64
   Property reference: #set( $monkey.Blame = $whitehouse.Leak )
65
   Method reference: #set( $monkey.Plan = $spindoctor.weave($web) )
66
   Number literal: #set( $monkey.Number = 123 )
67
   Range operator: #set( $monkey.Numbers = [1..3] )
68
   Object list: #set( $monkey.Say = ["Not", $my, "fault"] )
69
   Object map: #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"})
70
71
The RHS can also be a simple arithmetic expression, such as:
72
Addition: #set( $value = $foo + 1 )
73
   Subtraction: #set( $value = $bar - 1 )
74
   Multiplication: #set( $value = $foo * $bar )
75
   Division: #set( $value = $foo / $bar )
76
   Remainder: #set( $value = $foo % $bar )
77
78

MIME types defined: text/velocity.