Back to ModuleHelper class

Method getLayoutPath

public static string
getLayoutPath
(mixed $module, mixed $layout = 'default')
Get the path to a layout for a module
Parameters
  • string $module The name of the module
  • string $layout The name of the module layout. If alternative layout, in the form template:filename.
Returns
  • string The path to the module layout
Since
  • 1.5
Class: ModuleHelper
Project: Joomla

Method getLayoutPath - Source code

/**
 * Get the path to a layout for a module
 *
 * @param   string  $module  The name of the module
 * @param   string  $layout  The name of the module layout. If alternative layout, in the form template:filename.
 *
 * @return  string  The path to the module layout
 *
 * @since   1.5
 */
public static function getLayoutPath($module, $layout = 'default')
{
    $templateObj = Factory::getApplication()->getTemplate(true);
    $defaultLayout = $layout;
    $template = $templateObj->template;
    if (strpos($layout, ':') !== false) {
        // Get the template and file name from the string
        $temp = explode(':', $layout);
        $template = $temp[0] === '_' ? $template : $temp[0];
        $layout = $temp[1];
        $defaultLayout = $temp[1] ?: 'default';
    }
    $dPath = JPATH_BASE . '/modules/' . $module . '/tmpl/default.php';
    try {
        // Build the template and base path for the layout
        $tPath = Path::check(JPATH_THEMES . '/' . $template . '/html/' . $module . '/' . $layout . '.php');
        $iPath = Path::check(JPATH_THEMES . '/' . $templateObj->parent . '/html/' . $module . '/' . $layout . '.php');
        $bPath = Path::check(JPATH_BASE . '/modules/' . $module . '/tmpl/' . $defaultLayout . '.php');
    } catch (\Exception $e) {
        // On error fallback to the default path
        return $dPath;
    }
    // If the template has a layout override use it
    if (is_file($tPath)) {
        return $tPath;
    }
    if (!empty($templateObj->parent) && is_file($iPath)) {
        return $iPath;
    }
    if (is_file($bPath)) {
        return $bPath;
    }
    return $dPath;
}