You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Matthias David <Ma...@ptv.de> on 2003/01/08 16:22:34 UTC

Writing own foreach-macro

Hi,

is it possible to write an own foreach-macro? E.g. something like this

#macro { myForeach param1 param2 }
...
#end

And then use it as follows:

#myForeach x y
...
#end

I have no idea how to do this, as I don't know if you can call a macro with
an #end directive. If it is possible: How do I access the enclosing text
within the macro definition?

Thanks for any hints,
 Matthias.

Re: Writing own foreach-macro

Posted by Claude Brisson <cl...@savoirweb.com>.



> Hi,
> 
> is it possible to write an own foreach-macro? E.g. something like this
> 
> #macro { myForeach param1 param2 }
> ...
> #end
> 
> And then use it as follows:
> 
> #myForeach x y
> ...
> #end
> 
> I have no idea how to do this, as I don't know if you can call a macro with
> an #end directive. If it is possible: How do I access the enclosing text
> within the macro definition?
> 
> Thanks for any hints,
>  Matthias.
> 

Not this way, but you can do :

#macro (myForeach $list)
    #foreach ($item in $list)
    ...
    #end
#end

and :

#myForeach(['x','y',"$z"])






CloD



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>