Back to SiteApplication class

Method setTemplate

public void
setTemplate
(mixed $template, mixed $styleParams = null)
Overrides the default template that would be used
Parameters
  • \stdClass|string $template The template name or definition
  • mixed $styleParams The template style parameters
Returns
  • void
Since
  • 3.2

Method setTemplate - Source code

/**
 * Overrides the default template that would be used
 *
 * @param   \stdClass|string $template    The template name or definition
 * @param   mixed            $styleParams The template style parameters
 *
 * @return  void
 *
 * @since   3.2
 */
public function setTemplate($template, $styleParams = null)
{
    if (is_object($template)) {
        $templateName = empty($template->template) ? '' : $template->template;
        $templateInheritable = empty($template->inheritable) ? 0 : $template->inheritable;
        $templateParent = empty($template->parent) ? '' : $template->parent;
        $templateParams = empty($template->params) ? $styleParams : $template->params;
    } else {
        $templateName = $template;
        $templateInheritable = 0;
        $templateParent = '';
        $templateParams = $styleParams;
    }
    if (is_dir(JPATH_THEMES . '/' . $templateName)) {
        $this->template = new \stdClass();
        $this->template->template = $templateName;
        if ($templateParams instanceof Registry) {
            $this->template->params = $templateParams;
        } else {
            $this->template->params = new Registry($templateParams);
        }
        $this->template->inheritable = $templateInheritable;
        $this->template->parent = $templateParent;
        // Store the template and its params to the config
        $this->set('theme', $this->template->template);
        $this->set('themeParams', $this->template->params);
    }
}