On Tue, Sep 6, 2011 at 2:59 PM, Mark Wallace <[email protected]> wrote: > On 9/6/2011 8:40 AM, Vincent Massol wrote: >> >> Hi Mark, >> >> On Sep 6, 2011, at 2:15 PM, Mark Wallace wrote: >> >>> On 9/3/2011 3:08 AM, Vincent Massol wrote: >>>> >>>> Hi, >>>> >>>> On Sep 2, 2011, at 10:48 PM, Mark Wallace wrote: >>>> >>>> >>>>> I have a macro (implemented in Java) with this interface: >>>>> >>>>> public List<Block> execute(InferenceParameter parameters, String >>>>> content, MacroTransformationContext context) ; >>>>> >>>>> I want to call this macro from within a velocity script. When I do, it >>>>> returns a List<Block>. How do I get the velocity script to render the >>>>> List<Block> properly? >>>>> >>>> You could check the tutorial at >>>> http://rendering.xwiki.org/xwiki/bin/view/Main/ExtendingMacro >>>> (check the deployment at the end). >>>> >>>> >>> I'm not having a problem invoking the macro in a wiki page. But >>> sometimes I'd like to invoke it from within a larger velocity script. I.e. >>> >>> I can do this: >>> {{mymacro param="hello"/}} >>> But I'd also like to do this: >>> {{velocity}} >>> #set($words = ["Some", "velocity", "code"]) >>> #foreach($word in $words) >>> $word ## >>> $services.mymacro($word) >>> #end >>> {{/velocity}} >>> I didn't see anything in the deployment part of the tutorial about doing >>> this. >> >> I was going to respond the following: >> >> ----- >> Your first use case is a macro while your second one isn't. The second use >> case is simply a programmatic service or API that you wish to expose. Macros >> are not supposed to return anything. >> >> To implement your second use case you'd create a Script Service component >> in java, see >> http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Module >> >> Now there's another possibility which is to: >> * call your macro using a groovy script. You'll need to look it up and >> call its execute method. This will return a List of Blocks >> * still in the groovy macro code, lookup a renderer and tell it to render >> the list of blocks. >> >> This is slightly more tricky and I don't see why you'd want to do this >> TBH. To help you further we'd need to know more about your specific use >> case. >> ----- >> >> But I just understood that you simply want to render the macro from inside >> your velocity script. So you'd just need to do this: >> >> {{velocity}} >> #set($words = ["Some", "velocity", "code"]) >> #foreach($word in $words) >> $word ## >> {{mymacro param="$word"/}} >> #end >> {{/velocity}} >> >> Hope it helps, >> -Vincent > > Yes, this is all I needed. Didn't realize I could invoke it inline. Not > sure how I missed that! Thanks!
Be just aware that the macro is actually executed after the whole velocity is executed. What really happen is that you produce wiki syntax with your velocity script which is then interpreted and macros are wiki syntax. > -Mark > > > > _______________________________________________ > devs mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/devs > > -- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

