Tony Landis home

JSON Plugin for Smarty

This is a simple plugin for Smarty to retrieve and parse JSON data into an object in Smarty. Requires the PECL JSON.php class or PHP 5.2.0.

Instructions

  1. If your PHP version is < 5.2.0 Download the required JSON.php class and save it to your include path if it is not already there. If your PHP version is >= 5.2.0, this class is not needed, we will use the native json_decode() function.
  2. Download the JSON Smarty Plugin PHP Function File> (shown in the gist below) as function.json.php in your smarty\plugins\ directory.

Example plugin usage in Smarty templates files:

{json url=http://site.com/data.json resource=result}

The $result variable now contains the parsed JSON data.

blog comments powered by Disqus