vspatil
November 25, 2008, 7:13pm
1
I’ve created a custom macro and added it to the rx_assembly.vm file, but I’m not able to access it in my velocity template. For example,
macro to replace any pipes (|) or carats (^) with escaped characters
#macro (at_escapePipeCarat $str) $str.replace(’|’,’%7C’).replace(’^’,’%5E’)
#end
Call in template:
#set ($url = “&hello|world^?”)
#at_escapePipeCarat ("$url")
#at_escapePipeCarat ($url)
Output:
#at_escapePipeCarat ("&hello|world^?")
#at_escapePipeCarat (&hello|world^?)
Do I need to restart the Rx application or register the macro somewhere?
Thanks,
Veeren
Does it work if you define the macro in the template itself, or put
$url.replace('|','%7C').replace('^','%5E')
in the template? (Not sure if the syntax is correct.)
Or you could try putting each statement on a new line. (You can prevent whitespace being added by adding ## on the end of all lines, to comments out the carriage return.
Andrew.
You need to restart the server or pass sys_reinit=true parameter with a preview request. This will cause the macro file to be reloaded.
I restarted the server and the call to the macro is now working.
Thank you all for the help,
Veeren