【问题标题】:Magento - Move cart dropdown plugin to top.links. Reference name="top.Links" not changing locationMagento - 将购物车下拉插件移动到 top.links.参考名称=“top.Links”不改变位置
【发布时间】:2012-08-20 00:54:28
【问题描述】:

我正在使用的购物车下拉插件具有以下 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"

我也尝试复制该块并将其粘贴到 &lt;reference name="top.links"&gt; 下的 local.xml 中,然后将其放入 page.xml 中,但无济于事。



【问题讨论】:

    标签: xml magento themes


    【解决方案1】:

    应该是&lt;reference name="top.links"&gt;,正如属性所说->引用NAME

    不显示的问题是: - 看top.links的定义 -> &lt;block type="page/template_links" name="top.links" as="topLinks"/&gt; - 那就去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.links 扩展自core/template。 对于那些从core/template 扩展的块需要一个模板(不是很简单), 它将显示模板内的所有内容(在您的情况下,模板是page/template/links.phtml

    对于一个模板,为了能够渲染它的子模板,它应该显式调用getChildHtml

    &lt;?php echo $this-&gt;getChildHtml(); ?&gt; -> 将渲染它下面的所有子节点

    &lt;?php echo $this-&gt;getChildHtml('cartheader_sidebar'); ?&gt; -> 将呈现具有别名/名称cartheader_sidebar 的孩子

    意思是如果你想让cartheader_sidebar显示在top.links中,你需要把&lt;?php echo $this-&gt;getChildHtml('cartheader_sidebar'); ?&gt;放在page/template/links.phtml

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多