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.

eZ debug

Timing: Jan 31 2025 01:25:23
Script start
Timing: Jan 31 2025 01:25:23
Module start 'layout'
Timing: Jan 31 2025 01:25:23
Module start 'content'
Timing: Jan 31 2025 01:25:23
Module end 'content'
Timing: Jan 31 2025 01:25:23
Script end

Main resources:

Total runtime0.0222 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 588.1094151.1953
Module start 'layout' 0.00470.0041 739.3047220.6563
Module start 'content' 0.00880.0119 959.9609997.7734
Module end 'content' 0.02070.0014 1,957.734433.9922
Script end 0.0222  1,991.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002511.1664140.0002
Check MTime0.00104.6460140.0001
Mysql Total
Database connection0.00062.646010.0006
Mysqli_queries0.002410.994430.0008
Looping result0.00000.080610.0000
Template Total0.00104.610.0010
Template load0.00083.633610.0008
Template processing0.00020.896310.0002
Override
Cache load0.00052.349410.0005
General
dbfile0.00031.257480.0000
String conversion0.00000.045140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs