/** * creates a template object * * @param string $template the resource handle of the template file * @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 * @param boolean $do_clone flag is Smarty object shall be cloned * * @return object template object */ public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) { if ($cache_id !== null && (is_object($cache_id) || is_array($cache_id))) { $parent = $cache_id; $cache_id = null; } if ($parent !== null && is_array($parent)) { $data = $parent; $parent = null; } else { $data = null; } $_templateId = $this->getTemplateId($template, $cache_id, $compile_id); if (isset($this->template_objects[$_templateId])) { if ($do_clone) { $tpl = clone $this->template_objects[$_templateId]; $tpl->smarty = clone $tpl->smarty; } else { $tpl = $this->template_objects[$_templateId]; } $tpl->parent = $parent; $tpl->tpl_vars = array(); $tpl->config_vars = array(); } else { $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id); if ($do_clone) { $tpl->smarty = clone $tpl->smarty; } $tpl->templateId = $_templateId; } // fill data if present if (!empty($data) && is_array($data)) { // set up variable values foreach ($data as $_key => $_val) { $tpl->tpl_vars[$_key] = new Smarty_Variable($_val); } } if ($this->debugging) { Smarty_Internal_Debug::register_template($tpl); } return $tpl; }
/** * Template code runtime function to set up an inline subtemplate * * @param string $template the resource handle of the template file * @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 integer $caching cache mode * @param integer $cache_lifetime life time of cache data * @param array $data passed parameter template variables * @param null|int $parent_scope scope in which {include} should execute * @param null $parent * * @return \Smarty_Internal_Template */ public function setupTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data = array(), $parent_scope = null, Smarty_Internal_Data $parent = null, $mode = null) { if ($mode !== null) { $data = array(); if (isset($cache_id)) { if (is_object($cache_id)) { $parent = $cache_id; $cache_id = null; } elseif (is_array($cache_id)) { $data = $cache_id; $cache_id = null; } } if (isset($parent)) { if (is_array($parent)) { $data = $parent; if ($mode > 1) { $parent = $this; } else { $parent = null; } } } elseif ($mode > 1) { $parent = $this; } } $tpl = null; $_templateId = ''; if ($this->template_resource_caching || !empty($this->template_objects) || $mode == 4) { $_templateId = $this->getTemplateId($template, $cache_id, $compile_id); // already in template cache? if (isset($this->template_objects[$_templateId])) { // clone cached template object because of possible recursive call $tpl = clone $this->template_objects[$_templateId]; $tpl->parent = $parent; if ((bool) $tpl->caching !== (bool) $caching) { unset($tpl->compiled); } $tpl->caching = $caching; $tpl->cache_lifetime = $cache_lifetime; } } if (!isset($tpl)) { $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id, $caching, $cache_lifetime); if ($this->template_resource_caching && $mode > 3 || $mode == 4) { $this->template_objects[$_templateId] = $tpl; } } if (isset($parent_scope)) { // get variables from calling scope if ($parent_scope == Smarty::SCOPE_LOCAL) { $tpl->tpl_vars = $parent->tpl_vars; $tpl->config_vars = $parent->config_vars; } elseif ($parent_scope == Smarty::SCOPE_PARENT) { $tpl->tpl_vars =& $parent->tpl_vars; $tpl->config_vars =& $parent->config_vars; } elseif ($parent_scope == Smarty::SCOPE_GLOBAL) { $tpl->tpl_vars =& Smarty::$global_tpl_vars; $tpl->config_vars =& $this->config_vars; } elseif ($parent_scope == Smarty::SCOPE_ROOT) { $ptr = $tpl->parent; while (!empty($ptr->parent)) { $ptr = $ptr->parent; } $tpl->tpl_vars =& $ptr->tpl_vars; $tpl->config_vars =& $ptr->config_vars; } } if (!empty($data)) { // set up variable values foreach ($data as $_key => $_val) { $tpl->tpl_vars[$_key] = new Smarty_Variable($_val); } } if ($this->debugging) { Smarty_Internal_Debug::register_template($tpl); } return $tpl; }