Sankar Subburaj
Sankar Subburaj

Reputation: 5042

In magento how to find layout type?

I need to check which type of layout/page was loaded currently in magento.

I mean 1column or 2column-left or 2column-right or 3column.

I need to find programmatically...

How can I do, I googled but no help there.

Upvotes: 1

Views: 1851

Answers (3)

benmarks
benmarks

Reputation: 23205

What are you trying to do? Programmatic coupling with rendering context might indicate a better approach is available. That said:

You can ask the layout object if a root block has been instantiated, and if so, what its template property is:

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

if ($root) {
    $rootTpl = $root->getTemplate(); // For core/design_package calculated
                                     // absolute path use getTemplateFile();

    switch ($rootTpl) {
        case 'page/1column.phtml':
            //stuff to do
            break;

        //etc.
    }
}

Upvotes: 6

Jevgeni Smirnov
Jevgeni Smirnov

Reputation: 3797

You can check the first child of the div.page to know how many columns in the current template.

html body div.wrapper div.page div.main-container.col1-layout

Upvotes: 0

edsk
edsk

Reputation: 58

Check the XML files in the /app/design/frontend/default/--your theme--/layout folder. They contain references to the template files used.

E.g. page.xml contains:

<block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">

... which defines the template used for most of the pages.

Good luck!

Upvotes: 0

Related Questions