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());
}
}