diff --git a/Readme.md b/Readme.md index a76aae5..cd040f1 100644 --- a/Readme.md +++ b/Readme.md @@ -10,6 +10,7 @@ Placid allows you to consume RESTful APIs in your Statamic templates, using Guzz - Access tokens #### Updates / Changes +- **v1.0.2** - Fixes issue when an API returns an array and you was unable to access its values or loop it - **v1.0.0** - Version 1, fixes and enhancements - **v0.9.2** - Refactoring and added [API](#api) methods - **v0.9** - Bug fixes, refactoring, added [default](#defaults) config and reusable [access tokens](#access_tokens) @@ -93,6 +94,14 @@ To use this plugin in your templates, simply use these tags: *If you are unsure as to what tags to use within the placid variable pair, just pop the api url into your browser and work it out from there* +If your API returns an array then Placid will automatically cast this to a `response` variable which you can loop over like: + + {{ placid handle="tester" }} + {{ response }} + {{ some.value }} + {{ /response }} + {{ /placid }} + ### Queries You can add queries to the request from the template using a `key:value` pattern separated by commas (`,`), something like this: diff --git a/placid/pi.placid.php b/placid/pi.placid.php index 625032c..89cf6ba 100644 --- a/placid/pi.placid.php +++ b/placid/pi.placid.php @@ -4,7 +4,7 @@ class Plugin_placid extends Plugin { var $meta = array( 'name' => 'Placid', - 'version' => '1.0.0', + 'version' => '1.0.2', 'author' => 'Alec Ritson', 'author_url' => 'http://www.alecritson.co.uk' ); @@ -188,7 +188,11 @@ public function index() if(!$result) { return Parse::template($this->content, array('no_results' => true)); } - + + if(is_array($result)) + { + return Parse::template($this->content, array('response' => $result)); + } return $result; } @@ -197,7 +201,6 @@ public function fetchParams($args) { foreach($args as $arg) { - $options[$arg] = $this->fetchParam($arg, NULL, NULL, FALSE, FALSE); } return array_filter($options);