Tristan Hall
Tristan Hall

Reputation: 13

How to Get the Name of Current Layout of a CMS Page in Magento?

Under the design tab of a CMS page in Magento's admin area, there is the option to specify a page layout. I have a few custom fields that I wish to display only on certain page layouts. How can I grab the name of the page layout so I can proceed with an if statement for displaying my custom fields? Thanks in advance!

Upvotes: 1

Views: 2983

Answers (2)

Sukeshini
Sukeshini

Reputation: 1261

$root = Mage::app()->getLayout()->getBlock('root');

if ($root) 
{
    $rootTemplate = $root->getTemplate(); 

    switch ($rootTemplate ) 
    {
        case 'page/2column.phtml':
            // Do something.
            break;

        //etc.
    }
}

Upvotes: 4

Mark1inLA
Mark1inLA

Reputation: 196

Congrats on finding your solution, but this may help you out moving forward: http://www.magentocommerce.com/magento-connect/magneto-debug-8676.html

I find it useful at times.

Upvotes: 1

Related Questions