From bc99747f9363599feb1834ad85e5f5b8073dd0bb Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Tue, 7 Jul 2015 02:01:45 +0200 Subject: [PATCH] - improvement allow fetch() or display() called on a template object to get output from other template like $template->fetch('foo.tpl') https://github.com/smarty-php/smarty/issues/70 --- change_log.txt | 4 ++++ libs/Smarty.class.php | 6 +++--- libs/sysplugins/smarty_internal_template.php | 20 ++++++++++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/change_log.txt b/change_log.txt index a699e676..967c3e9b 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,8 @@  ===== 3.1.28-dev===== (xx.xx.2015) + 07.07.2015 + - improvement allow fetch() or display() called on a template object to get output from other template + like $template->fetch('foo.tpl') https://github.com/smarty-php/smarty/issues/70 + 06.07.2015 - optimize {block} compilation - optimization get rid of __get and __set in source object diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 6eff1249..94af654b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/22'; + const SMARTY_VERSION = '3.1.28-dev/24'; /** * define variable scopes @@ -791,7 +791,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @throws SmartyException * @return string rendered template output */ - public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false) + public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false) { if ($cache_id !== null && is_object($cache_id)) { $parent = $cache_id; @@ -816,7 +816,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @param mixed $compile_id compile id to be used with this template * @param object $parent next higher level of Smarty variables */ - public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) + public function display($template, $cache_id = null, $compile_id = null, $parent = null) { // display template $this->fetch($template, $cache_id, $compile_id, $parent, true); diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 1ee3fc0e..4ceed831 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -133,21 +133,33 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase /** * fetches rendered template * + * @param string $template the resource handle of the template file or template object + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $parent next higher level of Smarty variables + * * @throws Exception * @throws SmartyException * @return string rendered template output */ - public function fetch() + public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) { - return $this->render(true, false, false); + return isset($template) ? $this->smarty->fetch($template, $cache_id, $compile_id, $parent) : $this->render(true, false, false); } /** * displays a Smarty template + * + * @param string $template the resource handle of the template file or template object + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $parent next higher level of Smarty variables + * + * @return string */ - public function display() + public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) { - $this->render(true, false, true); + return isset($template) ? $this->smarty->fetch($template, $cache_id, $compile_id, $parent, true) : $this->render(true, false, true); } /**