2019独角兽企业重金招聘Python工程师标准>>>
- velocimcro.library属性:指定自己的模板库,多个模板库以逗号分隔。默认情况下,velocity查找唯一的一个库:VM_global_library.vm
- velocimacro.permissions.allow.inline属性:是否允许开发者在普通模板内定义Velocity宏。ho
- velocimacro.permissions.allow.inline.replace.global属性: 是否允许设计者使用本地的inline的 宏替代全局的宏(全局的宏是指在velocimacro.library属性中指定的文件内定义的宏)。默认情况下,此值为false。这样就阻止本地的宏覆盖全局的。
- velocimacro.permissions.allow.inline.local.scale属性: inline定义的宏是否仅仅在被定义的template内可见. 默认是false。 换句话说,如果这个属性设置为true,一个inline定义的宏只能在定义它的template内使用。
- velocimacro.context.localscope属性: 默认值为false。当设置为true时,任何在宏内通过#set()对context的修改被认为是针对此宏的本地设置,而不会永久的影响内容。
- velocimacro.library.autoreload属性: 控制宏库的自动加载。默认是false。当设置为ture时,对于一个宏的调用将自动检查原始库是否发生了变化,如果变化将重新加载它。这个属性使得你可以不用重新启动servlet容器而达到重新加载的效果,就像你使用regular模板一样。这个属性可以使用的前提就是resource loader缓存是off状态(file.resource.loader.cache = false)。注意这个属性实际上是针对开发而非产品的。
## #include( “a.txt” ) renders as <ontents of a.txt>(注释行)#include( “a.txt” )## \#include( “a.txt” ) renders as \#include( “a.txt” )\#include( “a.txt” )## \\#include ( “a.txt” ) renders as \<contents of a.txt>\\#include( “a.txt” )
#if ( $jazz )Vyacheslav Ganelin#end
\#if ( $jazz )Vyacheslav Ganelin\#end
\\#if ( $jazz )Vyacheslav Ganelin\\#end
#set ( $imperial = [ “Munetaka”, “Koreyasu”, “Hisakira”, “Morikune” ] )
#foreach ( $shogun in $imperial )$shogun
#end
Send me #set($foo = [“$10 and”,”a cake”])#foreach($a in $foo)$a #end please.
Send me
#set ( $foo = [“$10 and “,”a cake”] )
#foreach ( $a in $foo )$a
#end
please.
Send me
#set($foo = [“$10 and “,”a cake”])#foreach ($a in $foo )$a#end please.
- 在模板中可以使用Velocity内建的算术函数,如:加、减、乘、除
#set ( $foo = $bar + 3 )
#set ( $foo = $bar - 4 )
#set ( $foo = $bar * 6 )
#set ( $foo = $bar / 2 )
#set ( $foo = $bar % 5 )
[n..m]
#foreach ( $foo in [1..5] )$foo
#end
Second example:#foreach ( $bar in [2..-2] )$bar
#end
#set ( $arr = [0..1] )
#foreach ( $i in $arr )$i
#end
[1..3]
注意:range operator只在#set和#foreach中有效。
Advanced Issue:Escaping and!
#set ( $foo = “bar” )
- Can I user a directive or another VM as an argument to a VM? For example, #center ( #bold( “hello” ) )
#set ( $stuff = "#bold( 'hello' )" )
#center ( $stuff )
#center ("#bold('hello')")
#macro ( inner $foo )inner : $foo
#end#macro ( outer $foo )#set ( $bar = "outerlala" )outer : $foo
#end#set ( $bar = 'calltimelala' )
#outer( "#inner($bar)" )
#macro ( foo $color )<tr bgcolor = $color ><td>Hi</td></tr><tr bgcolor = $color ><td>There</td></tr>
#end#foo ( $bar.rowColor() )
#set ( $color = $bar.rowColor() )
#foo ( $color )
- can I register velocimacros via #parse()?
- What is velocimacro autoreloading?
#set ( $size = “Big” )
#set ( $name = “Ben” )
The clock is $size$name.
#set ( $size = “Big” )
#set ( $name = “Ben” )
#set ( $clokc = “$size$name” )
The clock is $clock.
#set ( $size = "Big" )
#set ( $name = "Ben" )
#set ( $clock = "${size}Tall$name" )
The clock is $clock.