The basic usage of NVelocity

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

NVelocity commonly used grammar instruction

By default, NVelocity parsing is case insensitive, of course, you can set the runtime.strict.math=true, the strict analytical model. 
Strict case sensitive or sometimes quite useful. If there is a < in the template file; File=! --#include "aaa.html" --> contains a file that, when changing a template publication, will prompt #include behind no parentheses () error. Because in NVelocity, there are #include ("abc.html") this instruction. If we will change include to Include will not error. 

A reference to a variable: $ [ ! ][ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, _ ][ } ].

In NVelocity, a reference to a variable is begin with a $plus variable name. When using! Said when this variable is null, display an empty string. For example, when the $article is empty, it will display the “ $article“, article will display as $!“”. {}Limited to the variable name, variable name string will have sometimes, it is need to use {}. Such as $articleshow, would like to quote $article, then as long as the modified ${article} can. In fact, NVelocity will become the model for the entire template parsing.

The attribute reference: $ [ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, _ ]* .[a..z, A..Z ][ a..z, A-Z, 0..9, -, _ ]* [ } ] .

For example, $article.Title or${article.Title}.

A reference to the method: $ [ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, _ ]* .[ a..z, A..Z ][ a..z, A..Z, 0..9, -, _ ]*( [ optional parameter list... ] ) [ } ].

For example: $article.GetListByTitle ('nvelocity') or ${article.GetListByTitle ('nvelocity')}. In fact, attribute on object values can also be used $article.get_Title (obtained).

Assignment command#set: # [ { ] set [ } ] ( $ref = [ ", ' ]arg[ ", ' ] ).

For example: $article.Title='NVelocity', $$article.Categories=[1,2,3], of course, the right can also use complex expressions: $article.Title=$otherArticle.Title.SubString (0,3), the arithmetic expression: $article.Page=4/3. Attribute assignment can also use$article.set_Title('NVelocity').

Conditional instruction#if: # [ { ] if [ } ] ( [condition] ) [output] [ # [ { ] elseif [ } ] ( [condition] ) [output] ]* [ # [ { ] else [ } ] [output] ] # [ { ] end [ } ] .

The condition can be checked expression that returns bool. For example: #if ($article.Total> 1) $article.Title #else no data #end.

Instruction cycle#foreach: # [ { ] foreach [ } ] ($refinarg)statement# [ { ] end [ } ].

For example: #foreach($article in $articles) $article.Title #end.

A static resource instruction#include: # [ { ] include [ } ] ( arg[ arg2 ... argn] ).

For example: #include ('tmp.js'), the tmp.js contents of the file into the current stream. Of course you can use expressions: #include($article.Url).

Reference and analytical resources instruction#parse: # [ { ] parse [ } ] ( arg ).

For example: #parse ('tmp.js'), and #include different is, if there is a NVelocity in the tmp.js file processing instruction, will be variable, and put the results into the current flow.

Stop instruction stop: # [ { ] stop [ } ] .

When the NVelocity analysis to this instruction, will stop the parsing process. General user debugging.

Calculation of instruction#evaluate: # [ { ] evaluate [ } ] ( arg ).

For example: #evaluate ('$article.Title'), in the current output$article.Title

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Wright at November 17, 2013 - 7:26 AM