Re: [xwiki-users] Set plain output from within script
> > Vincent wrote: > > > {{velocity}} > > > #if("$!{request.xpage}" != 'plain') > > > $response.sendRedirect() #else > > > Hello world! > > > #end > > > {{/velocity}} > > > > > > > Thanks again for the quick response. That's a good suggestion, but I think > loses any query parameters that I'd passed to the page to use in the script. > > This is just an example, you can of course keep the query parameters passed > :) You have them in $request.queryString. > Aha, good point. Probably sending a 307 would trigger re-sending the POST data, too. $response.setStatus(307); $response.setHeader("Location", $doc.getURL('view', 'xpage=plain')); I will check it out later. ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Set plain output from within script
Hi Bryn, On 23 Sep 2015 at 07:48:15, Bryn Jeffries (bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) 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? 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). Thanks -Vincent ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Set plain output from within script
On Wed, Sep 23, 2015 at 9:27 AM, Bryn Jeffrieswrote: > 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. There is two different things, wiki="false" indicate that the source is plain text but by default the output is html so to make sure to have only your page content and rendered as plain text you can use add /get/ action and outputSyntax=plain in the URL as in: http://platform.xwiki.org/xwiki/bin/get/Main/SecondGenerationWiki?outputSyntax=plain See http://platform.xwiki.org/xwiki/bin/view/DevGuide/Standard+URL+Format#HAction:get and http://platform.xwiki.org/xwiki/bin/view/DevGuide/Standard+URL+Format#HParameter:outputSyntaxandoutputSyntaxVersion for more details. > ___ > users mailing list > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users -- Thomas Mortagne ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Set plain output from within script
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. ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Set plain output from within script
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
Re: [xwiki-users] Set plain output from within script
Vincent wrote: > {{velocity}} > #if("$!{request.xpage}" != 'plain') > $response.sendRedirect($doc.getURL('view', 'xpage=plain')) #else > Hello world! > #end > {{/velocity}} > Thanks again for the quick response. That's a good suggestion, but I think loses any query parameters that I'd passed to the page to use in the script. It's looking like I'll just have to include the extra parameter for now. I think I'm pushing against the way things are meant to be done in XWiki, but I don' really have time to align things better at present. Thanks, Bryn ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Set plain output from within script
On 23 Sep 2015 at 09:55:29, Bryn Jeffries (bryn.jeffr...@sydney.edu.au(mailto:bryn.jeffr...@sydney.edu.au)) wrote: > Vincent wrote: > > {{velocity}} > > #if("$!{request.xpage}" != 'plain') > > $response.sendRedirect($doc.getURL('view', 'xpage=plain')) #else > > Hello world! > > #end > > {{/velocity}} > > > > Thanks again for the quick response. That's a good suggestion, but I think > loses any query parameters that I'd passed to the page to use in the script. This is just an example, you can of course keep the query parameters passed :) You have them in $request.queryString. Thanks -Vincent > It's looking like I'll just have to include the extra parameter for now. I > think I'm pushing against the way things are meant to be done in XWiki, but I > don' really have time to align things better at present. > > Thanks, > > Bryn ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users