我偶然发现了这个问题,正在寻找类似的东西并想分享我的实现。也许它对那里的人有帮助。
以下将从可用模板列表中删除空的 2_columns_right 和 3_columns 布局。只需更改下面config.xml 中的remove_layouts 指令即可删除您要删除的任何内容。
我创建了一个模块(实际上是我为 magento 构建的第一个模块)并将以下内容放入文件 app/etc/modules/Labor_Templates.xml:
<?xml version="1.0"?>
<!--
/**
* This module changes the available templates. Only "1 column" and
* "2 column-left" will be available.
*/
-->
<config>
<modules>
<Labor_Templates>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</Labor_Templates>
</modules>
</config>
接下来,我们需要在/app/code/local/Labor/Templates/etc 中找到的config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Overrides the config to only allow "1 column" and "2 column left" layouts.
*/
-->
<config>
<modules>
<Labor_Templates>
<version>1.0.0</version>
</Labor_Templates>
</modules>
<global>
<models>
<template>
<class>Labor_Templates_Model</class>
</template>
<page>
<rewrite>
<config>Labor_Templates_Model_Config</config>
</rewrite>
</page>
</models>
<page>
<remove_layouts>
<layouts>empty,two_columns_right,three_columns</layouts>
</remove_layouts>
</page>
</global>
</config>
注意,我添加了remove_layouts 指令。最后我们编写自己的Labor_Templates_Model_Config 类:
<?php
/**
* Overrides the Overrides the core module Mage_Page_Model_Config in order to
* remove unused template layouts. This is done by handling remove_layout
* directives.
*/
class Labor_Templates_Model_Config extends Mage_Page_Model_Config {
const XML_PATH_PAGE_REMOVE_LAYOUTS = 'global/page/remove_layouts';
/**
* Initialize page layouts list
*
* @return Labor_Templates_Model_Config
*/
protected function _initPageLayouts()
{
parent::_initPageLayouts();
return $this->_removePageLayouts(self::XML_PATH_PAGE_REMOVE_LAYOUTS);
}
/**
* Removes page layouts found in the remove_layouts XML directive
*
* @return Labor_Templates_Model_Config
*/
protected function _removePageLayouts($xmlPath)
{
if (!Mage::getConfig()->getNode($xmlPath) || !is_array($this->_pageLayouts)) {
return $this;
}
foreach (explode(',', (string)Mage::getConfig()->getNode($xmlPath)->children()->layouts) as $toRemove) {
unset($this->_pageLayouts[$toRemove]);
}
return $this;
}
}
使用 Magento 1.7.0 工作和测试。