Dear Wiki user, You have subscribed to a wiki page or wiki category on "Jakarta-velocity Wiki" for change notification.
The following page has been changed by ShinobuKawaiYoshida: http://wiki.apache.org/jakarta-velocity/SilentParseInclude The comment on the change is: added more information ------------------------------------------------------------------------------ - Fred Toth's original solution for the singleton model can be found [http://mail-archives.apache.org/mod_mbox/jakarta-velocity-user/200405.mbox/[EMAIL PROTECTED] here]. + Fred Toth came up with a great idea on a "silent" #parse/#include. Unfortunately, it uses the !SingletonModel, which means that it does not work with the !VelocityViewServlet in VelocityTools 1.2. Here is the same solution written for 1.2. + Fred Toth's original solution can be found [http://mail-archives.apache.org/mod_mbox/jakarta-velocity-user/200405.mbox/[EMAIL PROTECTED] here]. + + * A mini "tool" for the tool box: {{{ package org.apache.velocity.tools.generic; @@ -46, +49 @@ } }}} + * A tool box entry: + {{{ + <tool> + <key>ftest</key> + <scope>application</scope> + <class>org.apache.velocity.tools.generic.TemplateExistsTool</class> + </tool> + }}} + * And a couple of macro definitions: + {{{ + #macro( cinclude $file )## + #if($ftest.exists($file))#include($file)#end## + #end + #macro( cparse $file )## + #if($ftest.exists($file))#parse($file)#end## + #end + }}} + With the above you can use these macros to get the job done: + {{{ + #cinclude("file_that_may_not_be_there") + #cparse("another_file_that_may_not_be_there") + }}} + If the files are not there, the macro silently evaluates to the empty string. If the files exist, you get the normal behavior. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
