user2071301
user2071301

Reputation: 77

Call Velocity Macro by Name

is it somehow possible to call a velocity macro by name e.g.:

#macro (sayHello)
 Hello!
#end

#set ($macroName = "sayHello")

#$macroName()

Thanks!

Upvotes: 3

Views: 661

Answers (2)

Evan Haas
Evan Haas

Reputation: 2564

A quick scan of the docs does not indicate support for this. But you could do something like the following:

#macro(myMacro1 $param1 $param2)
    ## stuff here...
#end

#macro(myMacro2 $param1 $param2)
    ## stuff here...
#end

#if($condition)
    #myMacro1
#else
    #myMacro2
#end

Or maybe your macro needs to take in additional parameters to account for all scenarios.

Upvotes: 0

Nathan Bubna
Nathan Bubna

Reputation: 6933

#set( $call = "#${macroname}()" )
#evaluate($call)

Upvotes: 4

Related Questions