API15

JModuleHelper/getLayoutPath: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Get the path to a layout for a module <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton...
 
Doxiki (talk | contribs)
No edit summary
Line 9: Line 9:


===Syntax===
===Syntax===
<source lang="php">static getLayoutPath($module, $layout= 'default')</source>
<source lang="php">getLayoutPath($module, $layout= 'default')</source>


  {| class="wikitable"
  {| class="wikitable"
Line 36: Line 36:
===Source Body===
===Source Body===
<source lang="php">
<source lang="php">
public static function getLayoutPath($module, $layout = 'default')
function getLayoutPath($module, $layout = 'default')
{
{
         $app = JFactory::getApplication();
         global $mainframe;


         // Build the template and base path for the layout
         // Build the template and base path for the layout
         $tPath = JPATH_BASE.'/templates/'.$app->getTemplate().'/html/'.$module.'/'.$layout.'.php';
         $tPath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.$module.DS.$layout.'.php';
         $bPath = JPATH_BASE.'/modules/'.$module.'/tmpl/'.$layout.'.php';
         $bPath = JPATH_BASE.DS.'modules'.DS.$module.DS.'tmpl'.DS.$layout.'.php';


         // If the template has a layout override use it
         // If the template has a layout override use it
         if (file_exists($tPath)) {
         if (file_exists($tPath)) {
                 return $tPath;
                 return $tPath;
         }
         } else {
        else {
                 return $bPath;
                 return $bPath;
         }
         }

Revision as of 22:09, 22 March 2010

Description

Get the path to a layout for a module

[Edit Descripton]

Template:Description:JModuleHelper/getLayoutPath

Syntax

getLayoutPath($module, $layout= 'default')
Parameter Name Default Value Description
$module $module The name of the module
$layout 'default' $layout The name of the module layout

Returns

string The path to the module layout

Defined in

libraries/joomla/application/module/helper.php

Importing

jimport( 'joomla.application.module.helper' );

Source Body

function getLayoutPath($module, $layout = 'default')
{
        global $mainframe;

        // Build the template and base path for the layout
        $tPath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.$module.DS.$layout.'.php';
        $bPath = JPATH_BASE.DS.'modules'.DS.$module.DS.'tmpl'.DS.$layout.'.php';

        // If the template has a layout override use it
        if (file_exists($tPath)) {
                return $tPath;
        } else {
                return $bPath;
        }
}

[Edit See Also] Template:SeeAlso:JModuleHelper/getLayoutPath

Examples

<CodeExamplesForm />