/** * Clear all the assigned template variables. * @return TemplateData current TemplateData instance for chaining */ public function clearAllAssign() { $this->tpl_vars = array(); if ($this->parent) { $this->applyDataFrom($this->parent->getTemplateVars()); } return $this; }
/** * Template code runtime function to get subtemplate content * * @param string $template the resource handle of the template file * @param mixed $compile_id compile id to be used with this template * @param array $vars optional variables to assign * @param int $parent_scope scope in which {include} should execute * @return void */ public function renderSubTemplate($template, $compile_id, $data, $parent_scope) { // Pass `true` for $suppressData; we're going to manage the scope setup ourselves $tpl = new Template($template, $this->smarty, $this, $compile_id, true); // get variables from calling scope if ($parent_scope == Brainy::SCOPE_LOCAL) { if (empty($data)) { $tpl->tpl_vars = $this->tpl_vars; // assign by value array } else { $tpl->cloneDataFrom($this); } $tpl->tpl_vars['smarty'] =& $this->tpl_vars['smarty']; } elseif ($parent_scope == Brainy::SCOPE_PARENT) { $tpl->tpl_vars =& $this->tpl_vars; } elseif ($parent_scope == Brainy::SCOPE_GLOBAL) { $tpl->tpl_vars =& Brainy::$global_tpl_vars; } elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) { $tpl->tpl_vars =& $this->tpl_vars; } else { $tpl->tpl_vars =& $scope_ptr->tpl_vars; } if (!empty($data)) { $tpl->applyDataFrom($data); } $tpl->display(); }
/** * @param string $reason * @param Template|null|void $template * @return void * @throws BrainyStrictModeException */ public function assertIsNotStrict($reason, $template = null) { if (Brainy::$strict_mode || $template && $template->isStrictMode()) { $this->trigger_template_error('Strict Mode: ' . $reason, null, '\\Box\\Brainy\\Exceptions\\BrainyStrictModeException'); } if ($this->parser && $this->parser->isStrictMode()) { $this->trigger_template_error('Strict Mode: ' . $reason, null, '\\Box\\Brainy\\Exceptions\\BrainyStrictModeException'); } }
/** * Template code runtime function to get subtemplate content * * @param string $template the resource handle of the template file * @param mixed $compile_id compile id to be used with this template * @param array $vars optional variables to assign * @param int $parent_scope scope in which {include} should execute * @return string template content */ public function getSubTemplate($template, $compile_id, $data, $parent_scope) { // already in template cache? $_templateId = $this->smarty->joined_template_dir . '#' . $template . $compile_id; if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } if (isset($this->smarty->template_objects[$_templateId])) { // clone cached template object because of possible recursive call $tpl = clone $this->smarty->template_objects[$_templateId]; $tpl->parent = $this; } else { $tpl = new Template($template, $this->smarty, $this, $compile_id); } // get variables from calling scope if ($parent_scope == Brainy::SCOPE_LOCAL) { $tpl->tpl_vars = $this->tpl_vars; $tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty']; } elseif ($parent_scope == Brainy::SCOPE_PARENT) { $tpl->tpl_vars =& $this->tpl_vars; } elseif ($parent_scope == Brainy::SCOPE_GLOBAL) { $tpl->tpl_vars =& Brainy::$global_tpl_vars; } elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) { $tpl->tpl_vars =& $this->tpl_vars; } else { $tpl->tpl_vars =& $scope_ptr->tpl_vars; } if ($data) { // set up variable values foreach ($data as $_key => $_val) { $tpl->tpl_vars[$_key] = new Variable($_val); } } return $tpl->fetch(null, null, null, null, false, false, true); }