This depends a lot on how the javascript is loaded...

If you're including it using $xwiki.jsx.use() then it won't have the same
context because it's a different HTTP request. If you use the macro and then
do a {{velocity}} macro with an {{html}} macro and a <script> inside of that,
the content will (should) be there.

Another solution is to pass the info in a parameter, eg:
$xwiki.jsx.use('My.Document', {"param": $value})
and then in the jsx extension...

var PARAMETER_ONE = "$escapetool.javascript($request.getParameter('param'))";

Thanks,
Caleb


On 05/13/2014 03:28 PM, Eduardo Abritta wrote:
> Exactly. I'm needing initialize a value in the velocity environment and use 
> it on the  javascript code.  it not needs to be dinamic.
> I am trying to use the following code but the JS variable is returning 
> "undefined"
>  
>  
> Java Script Code
>     var param;
>     this.param="$xcontext.macro.params.parameter";
>     console.log(param);
>  
> Velocity (Macro)
>  
>      $xcontext.put("param", $xcontext.macro.params.parameter)
> 
> Some light?
>  
> ty
> 
> 
> Atenciosamente,
> Eduardo Abritta
> e-mail: eduardo.abri...@outlook.com | 
>  
>> Date: Tue, 13 May 2014 10:05:17 +0200
>> From: jeremie.bousq...@gmail.com
>> To: users@xwiki.org
>> Subject: Re: [xwiki-users] Using parameter macro in the js extension
>>
>> Hi,
>>
>>
>> 2014-05-13 8:40 GMT+02:00 Michael Bußler <michael.buss...@googlemail.com>:
>>
>>> Hi, the velocity-code is executed on the server, while js-code runs on the
>>> client side, AFTER the macro-code was executed .
>>> You could try need to pass parameters to your macro via an URL parameter or
>>> http POST.
>>>
>>
>> Only if value needs to be refreshed without a page refresh. If value comes
>> from a velocity macro, it's in the context of a page, so it's enough to
>> initialize the javascript var from velocity (which is ok as velocity is
>> executed before) - it's not supposed to be updated server-side after the
>> page is rendered.
>> Of course if it needs to be dynamic you could go ajax.
>> Well my understanding of Eduardo is that he needs to initialize a value in
>> javascript, based on a macro parameter passed to a velocity macro.
>>
>>
>>>
>>> Hope this helps!
>>>
>>> Best, Michael
>>> Am 12.05.2014 19:01 schrieb "Eduardo Abritta" <eduardo.abri...@outlook.com
>>>> :
>>>
>>>> Hi Sirs,
>>>>
>>>> I am developing a macro in velocity (wiki macro) and need to use a
>>>> parameter (wiki macro parameter) defined by the user in my java script
>>> code
>>>> (java script extension). I tried  can several methods but it is not
>>> working.
>>>>
>>>> How can I do this?
>>>>
>>>>
>>>>
>>>>
>>>> Atenciosamente,
>>>> Eduardo Abritta
>>>> e-mail: eduardo.abri...@outlook.com |
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> users mailing list
>>>> users@xwiki.org
>>>> http://lists.xwiki.org/mailman/listinfo/users
>>>>
>>> _______________________________________________
>>> users mailing list
>>> users@xwiki.org
>>> http://lists.xwiki.org/mailman/listinfo/users
>>>
>> _______________________________________________
>> users mailing list
>> users@xwiki.org
>> http://lists.xwiki.org/mailman/listinfo/users
>                                         
> _______________________________________________
> users mailing list
> users@xwiki.org
> http://lists.xwiki.org/mailman/listinfo/users
> 
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to