Back to AdministratorApplication class

Method getTemplate

public string
getTemplate
(mixed $params = false)
Gets the name of the current template.
Parameters
  • bool $params True to return the template parameters
Returns
  • string The name of the template.
Since
  • 3.2
-
  • \InvalidArgumentException

Method getTemplate - Source code

/**
 * Gets the name of the current template.
 *
 * @param   boolean  $params  True to return the template parameters
 *
 * @return  string  The name of the template.
 *
 * @since   3.2
 * @throws  \InvalidArgumentException
 */
public function getTemplate($params = false)
{
    if (\is_object($this->template)) {
        if ($params) {
            return $this->template;
        }
        return $this->template->template;
    }
    $admin_style = (int) Factory::getUser()->getParam('admin_style');
    // Load the template name from the database
    $db = Factory::getDbo();
    $query = $db->getQuery(true)->select($db->quoteName(['s.template', 's.params', 's.inheritable', 's.parent']))->from($db->quoteName('#__template_styles', 's'))->join('LEFT', $db->quoteName('#__extensions', 'e'), $db->quoteName('e.type') . ' = ' . $db->quote('template') . ' AND ' . $db->quoteName('e.element') . ' = ' . $db->quoteName('s.template') . ' AND ' . $db->quoteName('e.client_id') . ' = ' . $db->quoteName('s.client_id'))->where([$db->quoteName('s.client_id') . ' = 1', $db->quoteName('s.home') . ' = ' . $db->quote('1')]);
    if ($admin_style) {
        $query->extendWhere('OR', [$db->quoteName('s.client_id') . ' = 1', $db->quoteName('s.id') . ' = :style', $db->quoteName('e.enabled') . ' = 1'])->bind(':style', $admin_style, ParameterType::INTEGER);
    }
    $query->order($db->quoteName('s.home'));
    $db->setQuery($query);
    $template = $db->loadObject();
    $template->template = InputFilter::getInstance()->clean($template->template, 'cmd');
    $template->params = new Registry($template->params);
    // Fallback template
    if (!is_file(JPATH_THEMES . '/' . $template->template . '/index.php') && !is_file(JPATH_THEMES . '/' . $template->parent . '/index.php')) {
        $this->getLogger()->error(Text::_('JERROR_ALERTNOTEMPLATE'), ['category' => 'system']);
        $template->params = new Registry();
        $template->template = 'atum';
        // Check, the data were found and if template really exists
        if (!is_file(JPATH_THEMES . '/' . $template->template . '/index.php')) {
            throw new \InvalidArgumentException(Text::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE', $template->template));
        }
    }
    // Cache the result
    $this->template = $template;
    // Pass the parent template to the state
    $this->set('themeInherits', $template->parent);
    if ($params) {
        return $template;
    }
    return $template->template;
}