AbstractView::initializeTemplate PHP Метод

initializeTemplate() публичный Метод

Called automatically during init for template initalization.
public initializeTemplate ( string $template_spot = null, string | array $template_branch = null ) : AbstractView
$template_spot string Where object's output goes
$template_branch string | array Where objects gets it's template
Результат AbstractView $this
    public function initializeTemplate($template_spot = null, $template_branch = null)
    {
        if ($template_spot === null) {
            $template_spot = $this->defaultSpot();
        }
        $this->spot = $template_spot;
        if (@$this->owner->template && !$this->owner->template->is_set($this->spot)) {
            throw $this->owner->template->exception('Spot is not found in owner\'s template')->addMoreInfo('spot', $this->spot);
        }
        if (!isset($template_branch)) {
            $template_branch = $this->defaultTemplate();
        }
        if (isset($template_branch)) {
            // template branch would tell us what kind of template we have to
            // use. Let's look at several cases:
            if (is_object($template_branch)) {
                // it might be already template instance (object)
                $this->template = $template_branch;
            } elseif (is_array($template_branch)) {
                // it might be array with [0]=template, [1]=tag
                if (is_object($template_branch[0])) {
                    // if [0] is object, we'll use that
                    $this->template = $template_branch[0];
                } else {
                    $this->template = $this->app->add('Template');
                    /** @type Template $this->template */
                    $this->template->loadTemplate($template_branch[0]);
                }
                // Now that we loaded it, let's see which tag we need to cut out
                $this->template = $this->template->cloneRegion(isset($template_branch[1]) ? $template_branch[1] : '_top');
            } else {
                // brach could be just a string - a region to clone off parent
                if (isset($this->owner->template)) {
                    $this->template = $this->owner->template->cloneRegion($template_branch);
                } else {
                    $this->template = $this->add('Template');
                }
            }
            /** @type Template $this->template */
            $this->template->owner = $this;
        }
        // Now that the template is loaded, let's take care of parent's template
        if ($this->owner && isset($this->owner->template) && !empty($this->owner->template)) {
            $this->owner->template->del($this->spot);
        }
        // Cool, now let's set _name of this template
        if ($this->template) {
            $this->template->trySet('_name', $this->getJSID());
        }
    }

Usage Example

Пример #1
0
 function initializeTemplate()
 {
     $l = $this->api->locate('addons', __NAMESPACE__, 'location');
     $lp = $this->api->locate('addons', __NAMESPACE__);
     $this->api->addLocation($lp, array('template' => 'templates/default'))->setParent($l);
     return parent::initializeTemplate();
 }
All Usage Examples Of AbstractView::initializeTemplate