Calling a speed macro by name

you can somehow call the speed macro by name, for example:

#macro (sayHello)
 Hello!
#end

#set ($macroName = "sayHello")

#$macroName()

      

Thank!

+3


source to share


2 answers


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

      



+4


source


A quick scan of the docs does not indicate support for this. But you can 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 should take additional parameters to account for all scenarios.

0


source







All Articles