在magento中按条件添加热门链接 [英] Add Top Links on condition basis in magento

查看:46
本文介绍了在magento中按条件添加热门链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点在自定义phtml中添加顶部链接.我删除了xml <remove name="top.links"/>中的链接块,现在在某些条件变为真之后,我想再次添加此块.当我将此代码用作顶部时菜单有效,但不适用于链接

I am little bit stuck with adding top links in my custom phtml.I removed the links block in my xml <remove name="top.links"/> , now after some condtion become true i want to add this block again.When i use this code for top menu it works but not for links

$block = Mage::getSingleton('core/layout');     
        echo $block->createBlock('catalog/navigation')->setTemplate('catalog/navigation/top.phtml')->toHtml();

这可以工作并显示顶部菜单.但是下面的代码没有显示任何内容.

This works and disply top menu.But the below code doesn't show anything.

        $block = Mage::getSingleton('core/layout');
        echo $block->createBlock('page/template_links')->setTemplate('page/template/links.phtml')->toHtml();

有帮助吗?

推荐答案

使用观察者后,我暂时解决了我的问题.我认为这是另一种方法.在我的配置中,我定义了oberser,如:

After using observer i solve my problem for time being.I think this is alternate way.In my config i define oberser like :

 <frontend>
        <events>
            <controller_action_layout_generate_xml_before>
                <observers>
                    <Mymodule>
                        <class>Mymodule_Model_Observer</class>
                        <method>addmyblock</method>
                    </Mymodule>
                </observers>
            </controller_action_layout_generate_xml_before>
        </events> 
</frontend>

在观察者中,只需检查并删除块:

while in oberser simply check and remove block :

<?php
class Mymodule_Model_Observer
{
    public function addmyblock(Varien_Event_Observer $observer)
    {
         if(Mage::getStoreConfig("mymodule/general/enable")==1) 
    {
        $layout = $observer->getLayout();
        $layout->getUpdate()->addUpdate('<remove name="top.search"/>
        <remove name="top.links"/>');              
         $layout->generateXml();
     }
    }
}.

我也从xml <remove name="top.links"/>中删除了代码.因此,仅当条件为true时,代码才删除代码块.

Also i removed the code from xml <remove name="top.links"/>.So the code only remove block when the condition become true.

这篇关于在magento中按条件添加热门链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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