cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oceatoon <t.katelb...@systheo.com>
Subject Re: JXTemplate macro: how to create "return value"?
Date Wed, 01 Dec 2004 18:08:37 GMT
H.vanderLinden@MI.unimaas.nl wrote:

> Hi guys,
> 
> I'm trying to create a jx:macro that does some processing and then stores
> the result in a variable. I would like this macro to behave as a function,
> i.e. pass the content of this variable to an external variable.
> 
> I've tried several approaches, but I don't get the result I want. Who can
> help?
> 
> From the dynamic repeater example I would assume that the following should
> work, but it doesn't.
> 
> <jx:macro name="myMacro">
>  <jx:parameter name="someParameter"/>
>  <!-- do some processing -->
>  <jx:set var="resultvar" value="${processingresult}"/>
>  <jx:evalBody/>
> </jx:macro>
> 
> 
> <jx:set var="getResult" value="blah"/>
> <myMacro someParameter="somevalue"/>
> <jx:set var="getResult" value="${resultvar}"/>
> </myMacro>
> 
> <p>${getResult}</p>
> 
> I would expect this to display the result of the macro, but it displays
> "blah".
> 
> Any idea?
> 
> Thanks.
> 
> Bye, Helma
Hi Helma

Variables seem to be restrained to the scope of the Macro (the same for
forEach), we work around this like this, maybe it'll work for you. 

declare a global variable(we use a hash but you can use any structure):

<jx:set var="globalvars" value="${java.util.HashMap(5)}"/>

<myMacro someParameter="somevalue"/>
<jx:set var="push" value="${resultvar}"/>
<jx:set var="dummy" value="${globalvars.put('getResult', resultvar)}"/>
</myMacro>

<p>${globalvars.getResult}</p>

Regards
Tibor



Mime
View raw message