【问题标题】:Magento2 move blockMagento2 移动块
【发布时间】:2015-08-07 13:43:59
【问题描述】:

我尝试替换默认折扣块。不幸的是,块总是位于容器的底部。我无法将其移动到默认块位置。

我的 xml -

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <remove name="checkout.cart.coupon"/>
        <referenceContainer name="cart.discount">
            <block class="{namespace}\Coupons\Block\Coupon" name="checkout.cart.coupon2" as="sadasdasd" template="test.phtml"/>
        </referenceContainer>
        <move element="cart.discount" destination="checkout.cart.container" before="checkout.cart.order.actions.gift_options" />
    </body>
    </page>

结果屏幕 -

【问题讨论】:

    标签: magento2


    【解决方案1】:

    我认为 checkout.cart.order.actions.gift_options 不是 checkout.cart.container 的直接子代,因此“before”子句没有找到您想要的位置,并且默认为“last child”作为默认行为.

    【讨论】:

    • 所以,我们在默认布局上有这个代码 - &lt;block class="Magento\Checkout\Block\Cart\Shipping" name="checkout.cart.shipping" as="shipping" template="cart/shipping.phtml"/&gt; &lt;block class="Magento\Checkout\Block\Cart\Coupon" name="checkout.cart.coupon" as="coupon" template="cart/coupon.phtml"/&gt; 我尝试使用 &lt;referenceContainer name="cart.discount"&gt; &lt;block class="{name}\Coupons\Block\Coupon" name="checkout.cart.coupon2" as="coupon2" template="coupon.phtml"/&gt; &lt;/referenceContainer&gt; &lt;move element="coupon2" destination="with-items" after="shipping" /&gt;
    • 但是这段代码不起作用。也许你可以给我代码的工作示例?
    猜你喜欢
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多