Magento - 将购物车下载插件移至top.links。引用名称=“top.Links”不改变位置

时间:2012-08-20 00:54:29

标签: xml magento themes

我正在使用的购物车下拉插件具有以下XML,我无法将其移至顶部链接。

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="addCss"  ifconfig="cartdrop/general/enabled"><stylesheet>css/cartdrop.css</stylesheet></action>
            <action method="addJs"  ifconfig="cartdrop/general/enabled"><script>lib/jquery-1.4.2.min.js</script></action>
            <action method="addJs"  ifconfig="cartdrop/general/enabled"><script>lib/cartdrop.js</script></action>
        </reference>

     <reference name="top.container">
            <!--<action method="setTemplate" ifconfig="cartdrop/general/enabled"><template>cartdrop/template/header.phtml</template></action>-->

<block type="core/template" name="cartheader_sidebar" template="cartdrop/cartheader.phtml">         
    <block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
        <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
        <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
        <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
        <block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions"/>
    </block>
</block>

        </reference>
    </default> 
</layout>

我尝试将引用名称更改为reference name="topLinks"reference name="top.Links"

我还尝试复制块并将其粘贴到<reference name="top.links">下的local.xml中并将其放在page.xml中但无济于事。



2 个答案:

答案 0 :(得分:0)

该属性应该是<reference name="top.links"> - &gt;参考名称

未显示的原因是: - 查看top.links - &gt;的定义<block type="page/template_links" name="top.links" as="topLinks"/> - 然后转到Mage/Page/Block/Template/Links.php

class Mage_Page_Block_Template_Links extends Mage_Core_Block_Template
{
    ...

    protected function _construct()
    {
        $this->setTemplate('page/template/links.phtml');
    }

    ...
}

现在我们知道top.linkscore/template延伸。 对于那些从core/template延伸的块需要一个模板(简单的不是它), 它将显示模板中的所有内容(在您的情况下,模板为page/template/links.phtml

对于模板,为了能够呈现其子项,它应该显式调用getChildHtml

<?php echo $this->getChildHtml(); ?> - &gt;将呈现其下的所有孩子

<?php echo $this->getChildHtml('cartheader_sidebar'); ?> - &gt;将使用别名/名称cartheader_sidebar

呈现孩子

这意味着如果您希望在cartheader_sidebar中显示top.links,则需要将<?php echo $this->getChildHtml('cartheader_sidebar'); ?>放入page/template/links.phtml

PS:我没有检查你的布局,我认为它已经是正确的

答案 1 :(得分:0)

布局XML:

 <block class="Magento\Framework\View\Element\Html\Link" name="cart-link" template="Magento_Theme::cart_link.phtml">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Cart</argument>
                <argument name="path" xsi:type="string" translate="true">#/</argument>
            </arguments>
        </block>

并且:

    <move element="minicart" destination="cart-link" />

cart_link.phtml:

 <li>My Cart
 <?php echo $block->getChildHtml('minicart');?>
 </li>