Validation error using a macro in global velocity includes
This is a implementation case which has been described in Sanfords blog post at:
https://blog.teknkl.com/velocity-poison-pill-throw-error-revisited/
I want to block sending an email if my velocity script has no output.
The idea is the use a global macro which has been defined in a Global Velocity token ( {{my.velocity includes}} )
#macro( throw_v2 $message )
#if( !$message.isEmpty() )
#evaluate( "${esc.h}set( ${message} )" )
#end
#end
In my email I include this token like {{my.velocity includes}}
Further in my email I include the next simple code ( as example )
#set( $output = '' )
#set( $nrOfLinksInOutput = 0 )
## render generated content
#if( $nrOfLinksInOutput == 0)
#throw_v2("ineligible")
#else
#set( $output = 'Links available' )
#end
${output}
In preview mode this code is executed properly, but when I try to approve my mail I receive the next error :
Validation Error approving OPER-3649-UPSELL-2022.TESTMAIL3 — <div>An error occurred when procesing the email Body! </div> <p>Encountered "ineligible" near</p> <div><pre ><p>#macro( throw_v2 $message )</pre><pre > #if( !$message.isEmpty() )</pre><pre class="x-form-item-label"> #evaluate( "${esc.h}set( ${message} )" )</pre><pre > #end</pre><pre >#end</p> #set( $output = '' )</pre></div>
Can someone help me here? What am I doing wrong?