Back to HtmlView class

Method _setPath

protected void
_setPath
(mixed $type, mixed $path)
Sets an entire array of search paths for templates or resources.
Parameters
  • string $type The type of path to set, typically 'template'.
  • mixed $path The new search path, or an array of search paths. If null or false, resets to the current directory only.
Returns
  • void
Since
  • 3.0
Class: HtmlView
Project: Joomla

Method _setPath - Source code

/**
 * Sets an entire array of search paths for templates or resources.
 *
 * @param   string  $type  The type of path to set, typically 'template'.
 * @param   mixed   $path  The new search path, or an array of search paths.  If null or false, resets to the current directory only.
 *
 * @return  void
 *
 * @since   3.0
 */
protected function _setPath($type, $path)
{
    if ($this->option) {
        $component = $this->option;
    } else {
        $component = ApplicationHelper::getComponentName();
    }
    $app = Factory::getApplication();
    // Clear out the prior search dirs
    $this->_path[$type] = array();
    // Actually add the user-specified directories
    $this->_addPath($type, $path);
    // Get the active template object
    $template = $app->getTemplate(true);
    // Always add the fallback directories as last resort
    switch (strtolower($type)) {
        case 'template':
            // Set the alternative template search dir
            if (isset($app)) {
                if ($component) {
                    $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component);
                }
                $name = $this->getName();
                if (!empty($template->parent)) {
                    // Parent template's overrides
                    $this->_addPath('template', JPATH_THEMES . '/' . $template->parent . '/html/' . $component . '/' . $name);
                    // Child template's overrides
                    $this->_addPath('template', JPATH_THEMES . '/' . $template->template . '/html/' . $component . '/' . $name);
                    break;
                }
                $this->_addPath('template', JPATH_THEMES . '/' . $template->template . '/html/' . $component . '/' . $name);
            }
            break;
    }
}