【问题标题】:Add Top Links on condition basis in magento在 magento 中根据条件添加热门链接
【发布时间】:2013-05-23 05:58:08
【问题描述】:

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

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

这有效并显示顶部菜单。但下面的代码没有显示任何内容。

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

任何帮助???

【问题讨论】:

    标签: magento magento-1.7


    【解决方案1】:

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

     <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>
    

    在 oberser 中只需检查并删除块:

    <?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 &lt;remove name="top.links"/&gt; 中删除了代码。因此,代码仅在条件为真时删除块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      相关资源
      最近更新 更多