I inherited several projects that use some Velocity code. http://velocity.apache.org/
My question may be simple and perhaps a bit naive to those who are more experienced with Velocity, but I have to fix bugs that deal with extra spaces
or missing spaces
in the code.
#if (${INCOMPLETE_ACCOUNT})Click "Use Now" to confirm your new Acme ID account $!{MM_ID}. You will be asked to create a password if you haven’t already done so. #elseClick below to download or sign into your new products.#end
Is this valid? I asked co-workers whether we need spaces before or after the else
and end
, but they claimed they didn't know. Someone said, "Always put a space before #end
." However, they don't actually follow that rule.
I found some documentation that explained that the else
within text (as in my example above) should be used like so:
#if( $foo == $bar)it's true!#{else}it's not!#end
(See: http://people.apache.org/~henning/velocity/html/ch05s03.html)
Question: Where do I need spaces? And is #{else}
currently safe to use? Is there one way that's recommended? How are you using #if
, #else
and #end in your code?
You don't need spaces in velocity:
Velocity's behaviour is to gobble up excess whitespace.
#set($foo=["$10 and ","a pie"])#foreach($a in $foo)$a#end
Sometimes you can't add spaces because your file you are rendering is intolerant for spaces.
About writing text right after else with #{else}
, you can change to use velocity comments after, as suggested in mailing list:
#if( $foo == $bar)it's true!#else#**#it's not!#end