From 6fa764d9c9ca4dd59066d6d94ed61861b5aebffb Mon Sep 17 00:00:00 2001 From: itsgoingd Date: Mon, 10 Mar 2014 16:58:32 +0100 Subject: [PATCH 1/3] Fixed Twig view render method not using the data argument correctly. --- Twig.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Twig.php b/Twig.php index 9cd860e..7d524c7 100644 --- a/Twig.php +++ b/Twig.php @@ -86,7 +86,9 @@ public function render($template, $data = null) $env = $this->getInstance(); $parser = $env->loadTemplate($template); - return $parser->render($this->all(), $data); + $data = array_merge($this->all(), (array) $data); + + return $parser->render($data); } /** From d81db4e77b02910b0fcc32730ec37392249102b2 Mon Sep 17 00:00:00 2001 From: Thijs Wijnmaalen Date: Thu, 20 Mar 2014 21:50:48 +0100 Subject: [PATCH 2/3] Support array-based options argument for Smarty function {urlFor} --- SmartyPlugins/function.urlFor.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/SmartyPlugins/function.urlFor.php b/SmartyPlugins/function.urlFor.php index fc405a0..254878d 100644 --- a/SmartyPlugins/function.urlFor.php +++ b/SmartyPlugins/function.urlFor.php @@ -19,10 +19,21 @@ function smarty_function_urlFor($params, $template) if (isset($params['options'])) { - $options = explode('|', $params['options']); - foreach ($options as $option) { - list($key, $value) = explode('.', $option); - $opts[$key] = $value; + switch (gettype($params['options'])) { + case 'array': + $opts = $params['options']; + break; + + case 'string': + $options = explode('|', $params['options']); + foreach ($options as $option) { + list($key, $value) = explode('.', $option); + $opts[$key] = $value; + } + break; + + default: + throw new \Exception('Options parameter is of unknown type, provide either string or array'); } $url = \Slim\Slim::getInstance($appName)->urlFor($name, $opts); From f0a05ea0b654218e40de692ed7cddcad1cf4b828 Mon Sep 17 00:00:00 2001 From: silentworks Date: Thu, 3 Apr 2014 17:31:10 +0100 Subject: [PATCH 3/3] Update views with new version number and updated docs. --- README.md | 6 +++++- Smarty.php | 6 +++--- SmartyPlugins/function.baseUrl.php | 2 ++ SmartyPlugins/function.siteUrl.php | 2 +- SmartyPlugins/function.urlFor.php | 6 +++--- Twig.php | 6 +++--- TwigExtension.php | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5dfa6c6..cb3934e 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,11 @@ Inside your Smarty template you would write: {urlFor name="hello" options="name.Josh|age.26"} -You can easily pass variables that are arrays using the (.) or object using the (->) by doing: +or with the new array syntax: + + {urlFor name="hello" options=["name" => "Josh", "age" => "26"]} + +You can easily pass variables that are arrays as normal or using the (.): Hello {$name} diff --git a/Smarty.php b/Smarty.php index 8593cec..fcf5101 100644 --- a/Smarty.php +++ b/Smarty.php @@ -6,7 +6,7 @@ * @author Andrew Smith * @link http://www.slimframework.com * @copyright 2013 Josh Lockhart - * @version 0.1.0 + * @version 0.1.2 * @package SlimViews * * MIT LICENSE @@ -78,9 +78,9 @@ class Smarty extends \Slim\View * * This method will output the rendered template content * - * @param string $template The path to the template, relative to the templates directory. + * @param string $template The path to the template, relative to the templates directory. * @param null $data - * @return void + * @return string */ public function render($template, $data = null) { diff --git a/SmartyPlugins/function.baseUrl.php b/SmartyPlugins/function.baseUrl.php index fd5e15e..1ed33fd 100644 --- a/SmartyPlugins/function.baseUrl.php +++ b/SmartyPlugins/function.baseUrl.php @@ -6,6 +6,8 @@ * Type: function * Name: baseUrl * Purpose: outputs url for a function with the defined name method + * version 0.1.2 + * package SlimViews * ------------------------------------------------------------- */ function smarty_function_baseUrl($params, $template) diff --git a/SmartyPlugins/function.siteUrl.php b/SmartyPlugins/function.siteUrl.php index 11eaa0f..83dc37b 100644 --- a/SmartyPlugins/function.siteUrl.php +++ b/SmartyPlugins/function.siteUrl.php @@ -6,7 +6,7 @@ * Type: function * Name: siteUrl * Purpose: outputs url for a function with the defined name method - * version 0.1.0 + * version 0.1.2 * package SlimViews * ------------------------------------------------------------- */ diff --git a/SmartyPlugins/function.urlFor.php b/SmartyPlugins/function.urlFor.php index 254878d..b0d3ea7 100644 --- a/SmartyPlugins/function.urlFor.php +++ b/SmartyPlugins/function.urlFor.php @@ -1,13 +1,13 @@