On 23 Sep 2015 at 09:27:36, Bryn Jeffries 
(bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) wrote:

> I wrote:
> >> I have several scripts (Groovy and Velocity) that generate output that 
> >> should not be rendered as a Wiki page. This is necessary, for example, 
> >> when rendering JSON. As documented before 
> >> (http://extensions.xwiki.org/xwiki/bin/view/Extension/Output+JSON) , it's 
> >> possible to allow such content by including request parameters xpage=plain 
> >> and outputSyntax=plain. However, this approach requires all pages that 
> >> refer to the script to remember to include these parameters, which is 
> >> rather error prone.
> >>
> >> Is there a way for a script to explicitly disable rendering instead?
>  
> Vincent replied:
> > Yes, there is :)
> >
> > For Groovy, see 
> > http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Macro
> > (check the output and wiki parameters)
> >
> > For Velocity, see 
> > http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity+Macro
> > (same parameter names).
>  
> OK, so trying both options with a content body
>  
> {{velocity output="false" wiki="false"}}
> $response.setContentType('application/json')
> {
> "greeting" : "Hello",
> "location": "World"
> }
> {{/velocity}}
>  
> I get a document of Content-Script-Type text/javascript but with a 38KB file 
> of HTML containing the usual Wiki page content, which I'd like to avoid. I 
> think if I explicitly set xpage=plain in the request then the template skips 
> rendering this stuff, but what I was wondering was whether I could set this 
> from within my script instead.

ok so I misread. What you could do is redirect the page with:

{{velocity}}
#if("$!{request.xpage}" != 'plain')
  $response.sendRedirect($doc.getURL('view', 'xpage=plain'))
#else
  Hello world!
#end
{{/velocity}}

Thanks
-Vincent
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to