JSON feed of nodes

Author Message

Luigi Spagnolo

Monday 25 May 2009 11:42:29 am

Since I have to integrate Simile Exhibit (http://www.simile-widgets.org/exhibit/ ) inside ezPublish 4, I need to obtain lists of nodes encoded in a custom JSON format.
I looked for extensions already doing this task, but seems that the only one available (http://projects.ez.no/json) is not siutable for ezPublish 4.x. Can you confirm this?

If so, can you suggest me what is the simplest way to obtain ez nodes encoded in JSON format?
I've thought of introducing a view parameter "format" so that I would modify the pagelayout.tpl as follows:

{if $view_parameters.format|eq('json')}
{* Display the content in JSON format using additional external templates if needed... *}

{else}
{* Display the content in xHTML, as usual... *}

{/if}

Is there a better solution, also for what concerns performance?
Do you think is better to intervene on the tpl or creating a module in php?

Thank you in advance

Gaetano Giunta

Monday 25 May 2009 1:49:31 pm

The ggxmlview on projects.ez.no extension already provides a basis for creating json-formatting of nodes via the templating system. It can be taken as-is or as an example.

You can of course use an {if} inside your pagelayout to switch to the desired output format, but I would rather
a - set up a wildcard url-alias rule, so that eg. www.mysite.com/json/23 redirects to www.mysite.com/layout/set/json/content/view/json/23
b - use a different siteaccess, dedicated to json, where the default pagelayout and node_view_full templates are the json ones. This means you do not need to set up url-alias rules and will benefit from virtual urls

The advantage is that
- you keep your standard templates clean of json stuff
- you can set up a proper content-type header for json content

The thing you have to consider is the view-cache: by default only the full view of nodes benefits of it, so if you use a different view mode you will need to change your settings accordingly.

Principal Consultant International Business
Member of the Community Project Board

Luigi Spagnolo

Tuesday 26 May 2009 2:10:57 am

Thank you very much for your precious suggestions. :)

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.