Box\Brainy\Templates\TemplateBase::renderSubTemplate PHP Method

renderSubTemplate() public method

Template code runtime function to get subtemplate content
public renderSubTemplate ( string $template, mixed $compile_id, $data, integer $parent_scope ) : void
$template string the resource handle of the template file
$compile_id mixed compile id to be used with this template
$parent_scope integer 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();
    }