Magento 1.7+: How to use the page layout handle

青春壹個敷衍的年華 提交于 2019-12-04 16:50:10

Is this some concept I don't understand or just a plain bug?

Both? Neither? The information in the <page><layout>...</layout></page> node is used by both the category pages and CMS pages, but each system uses the the information differently, and neither system uses it in a way you'd expect. Here's a rundown on how category pages use this information.

The category page is rendered by the following controller action

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
public function viewAction()
{
    ...
}

This controller action doesn't have the standard loadLayout and renderLayout method calls. Instead, there's a lot of extra code in this method for adding layout handles and doing things between generating the blocks and rendering the final layout. The section we're interested in is this

$design = Mage::getSingleton('catalog/design');
$settings = $design->getDesignSettings($category);

#...other stuff we don't care about...

if ($settings->getPageLayout()) {
    $this->getLayout()->helper('page/layout')->applyTemplate($settings->getPageLayout());
}

When you save a category with your "Page Layout" in the Custom Design tab, the getPageLayout method call above should return company_category_overview. On category pages, Magento doesn't use this to apply a handle, instead it passes the values to the applyTemplate method. Here's that method in full.

#File: app/code/core/Mage/Page/Helper/Layout.php
public function applyTemplate($pageLayout = null)
{
    if ($pageLayout === null) {
        $pageLayout = $this->getCurrentPageLayout();
    } else {
        $pageLayout = $this->_getConfig()->getPageLayout($pageLayout);
    }

    if (!$pageLayout) {
        return $this;
    }

    if ($this->getLayout()->getBlock('root') &&
        !$this->getLayout()->getBlock('root')->getIsHandle()) {
            // If not applied handle
            $this->getLayout()
                ->getBlock('root')
                ->setTemplate($pageLayout->getTemplate());
    }

    return $this;
}

The pertinent parts are this line,

$pageLayout = $this->_getConfig()->getPageLayout($pageLayout);

which will load the information from your configuration

<label>Kategorie-Übersicht</label>
<template>page/1column.phtml</template>
<layout_handle>company_category_overview</layout_handle>

as a Varien_Object. Then, it will use this information to apply a template to the root block.

$this->getLayout()
->getBlock('root')
>setTemplate($pageLayout->getTemplate());

So, for category pages, the information in the <layout_handle/> node is never used. That's why your layout updates aren't being applied — Magento actually applies your handle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!