Skip to content

Commit

Permalink
- improvement allow fetch() or display() called on a template object …
Browse files Browse the repository at this point in the history
…to get output from other template

     like $template->fetch('foo.tpl') #70
  • Loading branch information
uwetews committed Jul 7, 2015
1 parent 5b40178 commit bc99747
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -791,7 +791,7 @@ public function __construct()
* @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;
Expand All @@ -816,7 +816,7 @@ public function fetch($template = null, $cache_id = null, $compile_id = null, $p
* @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);
Expand Down
20 changes: 16 additions & 4 deletions libs/sysplugins/smarty_internal_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,33 @@ public function __construct($template_resource, $smarty, $_parent = null, $_cach
/**
* 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);
}

/**
Expand Down

1 comment on commit bc99747

@gogowitsch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that solved my recursion problem.

Please sign in to comment.