Xml Magento-为某些类别设置替代布局
我有许多类别,我需要使用不同于标准类别布局的布局。不必在“管理”区域的“自定义设计”选项卡中重复XML代码的最佳方式是什么?我需要这样做的每个类别都是一个“品牌”,所以我想这可以作为magento认识到需要使用替代模板的一种常见方式 在此感谢您的帮助Xml Magento-为某些类别设置替代布局,xml,magento,templates,layout,categories,Xml,Magento,Templates,Layout,Categories,我有许多类别,我需要使用不同于标准类别布局的布局。不必在“管理”区域的“自定义设计”选项卡中重复XML代码的最佳方式是什么?我需要这样做的每个类别都是一个“品牌”,所以我想这可以作为magento认识到需要使用替代模板的一种常见方式 在此感谢您的帮助 谢谢您可以定义自定义布局句柄并在特定类别中调用它 首先,定义布局句柄(例如在主题的local.xml中): 然后,在后端的类别编辑页面中,只需输入“自定义布局更新”: 您可以定义自定义布局句柄,并在特定类别中调用它 首先,定义布局句柄(例如在主
谢谢您可以定义自定义布局句柄并在特定类别中调用它 首先,定义布局句柄(例如在主题的local.xml中):
然后,在后端的类别编辑页面中,只需输入“自定义布局更新”:
您可以定义自定义布局句柄,并在特定类别中调用它 首先,定义布局句柄(例如在主题的local.xml中):
然后,在后端的类别编辑页面中,只需输入“自定义布局更新”:
如果知道类别的ID,也可以在local.xml布局文件中定义所有更改,如下所示:
<layout>
<CATEGORY_4>
<!-- updates here -->
</CATEGORY_4>
</layout>
如果知道类别的ID,也可以在local.xml布局文件中定义所有更改,如下所示:
<layout>
<CATEGORY_4>
<!-- updates here -->
</CATEGORY_4>
</layout>
另一种选择是使用“页面布局”菜单,尽管它需要一些额外的工作 首先,创建一个新的扩展以添加布局和观察者(有许多用于创建扩展的教程;为了简洁起见,这里省略了这些教程)。在新扩展名的
config.xml
文件中(我使用Bats\u Coreextend
作为参考):
这将把alt\u类别
句柄添加到我们的布局中,以便可以引用它,并且您可以对页面进行必要的更改
最后,确保如上所述创建模板文件(即
page/alt category.phtml
)。另一种选择是使用“页面布局”菜单,尽管它需要一些额外的工作
首先,创建一个新的扩展以添加布局和观察者(有许多用于创建扩展的教程;为了简洁起见,这里省略了这些教程)。在新扩展名的config.xml
文件中(我使用Bats\u Coreextend
作为参考):
这将把alt\u类别
句柄添加到我们的布局中,以便可以引用它,并且您可以对页面进行必要的更改
最后,确保如上所述创建模板文件(即
page/alt category.phtml
)。这是我的第一个想法,但更新似乎没有生效。这是我的第一个想法,但更新似乎没有生效。
<layout>
<CATEGORY_4>
<!-- updates here -->
</CATEGORY_4>
</layout>
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Bats_Coreextend>
<version>0.1.0</version>
</Bats_Coreextend>
</modules>
<global>
<events>
<controller_action_layout_load_before>
<observers>
<addCategoryLayoutHandle>
<class>Bats_Coreextend_Model_Observer</class>
<method>addCategoryLayoutHandle</method>
</addCategoryLayoutHandle>
</observers>
</controller_action_layout_load_before>
</events>
<page>
<layouts>
<alt_category module="page" translate="label">
<label>Alt. Category (Desc. at bottom)</label>
<template>page/alt-category.phtml</template>
<layout_handle>page_alt_category</layout_handle>
</alt_category>
</layouts>
</page>
</global>
</config>
<?php
class Bats_Coreextend_Model_Observer extends Mage_Core_Model_Observer {
public function addCategoryLayoutHandle(Varien_Event_Observer $observer)
{
/** @var Mage_Catalog_Model_Category|null $category */
$category = Mage::registry('current_category');
if(!($category instanceof Mage_Catalog_Model_Category)) {
return;
}
if($category->getPageLayout()) {
/** @var Mage_Core_Model_Layout_Update $update */
$update = $observer->getEvent()->getLayout()->getUpdate();
/** NOTE: May want to add an additional
* conditional here as this will also cause the
* layout handle to appear on product pages that
* are within the category with the alternative
* layout.
*/
$update->addHandle($category->getPageLayout());
}
}
}