Magento通过系统变量动态更改布局 [英] Magento changes layout dynamically via system variable

查看:73
本文介绍了Magento通过系统变量动态更改布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以通过使用在我们自己的模块上设置的系统变量来动态更改Magento页面(例如产品类别页面)的布局?我希望能够通过自己的模块管理配置面板设置类别页面的默认布局.这样我就不必在每次要更改某个magento页面的默认布局时都处理那些令人困惑的XML布局文件.

Is there a way we could changes the layout of a Magento page (let's say a product category page) dynamically by using system variable which have been set on our own module? I want to be able to set my category page's default layout via my own module admin config panel. So that I don't have to deal with those confusing XML layout file each time I want to change my default layout for a certain magento page.

我知道,在phtml文件中,我们可以简单地通过调用Mage::getStoreConfig('module/scope/...')来调用我们自己模块的系统变量,以使用该系统变量.但是,如果我们想使用该系统变量来更改默认情况下在XML布局文件上设置的整个布局,该怎么办.

I know, on a phtml file, we could simply call our own module's system variable by calling Mage::getStoreConfig('module/scope/...') to use that system variable. but what if we want to use that system variable to change the whole layout which is set on the XML layout file by default.

我看不到任何方法可以在XML布局文件中提取该系统变量值.

I don't see any ways to pull that system variable value on the XML Layout file.

但是我很确定必须有一个正确的方法来做到这一点.到目前为止,这是我所掌握的最接近的线索

But I'm pretty sure there must be a right way to do that. So far, this is the closest clue that I've got

Magento-xml布局,是否为ifconfig指定值?

但是,对于我真正想要实现的目标,我仍然找不到任何直接答案

But, still, I couldn't find any direct answer for what I really want to achieve

这是我的config.xml的内容

this is the content of my config.xml

<config>
    <modules>
        <Prem_Spectra>
            <version>0.1.0</version>
        </Prem_Spectra>
    </modules>

    <global>
        <models>
            <spectra>
                 <class>Prem_Spectra_Model</class>
            </spectra>
        </models>

        <helpers>
            <prem_spectra>
                <class>Prem_Spectra_Helper</class>
            </prem_spectra>
        </helpers>

    </global>
</config>

推荐答案

使用布局xml和帮助器中的简单方法可以很容易地实现这一点.我在这里看不到对观察员有任何要求,或者其他任何过于详尽的要求.

This can be very easily achieved using layout xml and a simple method in your helper. I don't see any requirement for an observer here or anything else overly elaborate.

因此,根据您从自己的模块存储配置值更改所有类别页面布局的要求,您将在布局xml中需要以下内容:

So, based on your requirements to change all category page layouts from your own modules store config value you will require the following in your layout xml:

<catalog_category_view>
    <reference name="root">
        <action method="setTemplate">
            <template helper="yourmodule/switchTemplate" />                  
        </action>
    </reference>
</catalog_category_view>

以及模块中的以下默认帮助器:

And the following in your modules default helper:

public function switchTemplate()
{
    $template = Mage::getStoreConfig('path_to/yourmodule/config');
    return $template;
}

这篇关于Magento通过系统变量动态更改布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆