Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dollar and exclamation mark (bang) symbols in VTL

I've recently encountered these two variables in some Velocity code:

$!variable1
!$variable2

I was surprised by the similarity of these so I became suspicious about the correctness of the code and become interested in finding the difference between two.

Is it possible that velocity allows any order of these two symbols or do they have different purpose? Do you know the answer?

like image 259
Jr. Avatar asked Oct 16 '25 20:10

Jr.


1 Answers

@Jr. Here is the guide I followed when doing VM R&D: http://velocity.apache.org/engine/1.7/user-guide.html

Velocity uses the !$ and $! annotations for different things. If you use !$ it will basically be the same as a normal "!" operator, but the $! is used as a basic check to see if the variable is blank and if so it prints it out as an empty string. If your variable is empty or null and you don't use the $! annotation it will print the actual variable name as a string.

like image 152
Francois Du Toit Avatar answered Oct 19 '25 14:10

Francois Du Toit