Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

The documentation is here

An if statement looks like this

    #if( $user.userId )

An if-elseif-else looks like this

#if( $foo < 10 )
    <strong>Go North</strong>
#elseif( $foo == 10 )
    <strong>Go East</strong>
#elseif( $bar == 6 )
    <strong>Go South</strong>
    <strong>Go West</strong>

A for loop looks like: $velocityCount is a 1-based counter of which element you are on in the loop.

     #foreach( $transaction in $transactionList )

Values can be output by ${…} or $… There is a particular case where the ${…} notation should be used, but the case eludes me right now.


If the value of ${data.firstName} does not exist, then ${data.firstName} will be outputted. To get around that, use the $!… notation. Then if it doesn’t exist, nothing will be outputted.


Setting a variable during the processing of the template is like

#set( $rowCss = "odd")

<tr class="$!rowCss">

Setting an array variable is very similar to setting a regular variable.

#set($platformsClasses = ['desktop','mobile bxslider'] )

Iterating over the array variable is the same as it is for any iterable item.

        #set($platformsClasses = ['desktop','mobile bxslider'] )
		#foreach($platformClass in $platformsClasses)
            <ul class="$platformClass">
                /* ... */

February 20th, 2014

Posted In: java ninja, Javaninja, templating, velocity


Leave a Comment

WP to LinkedIn Auto Publish Powered By :