3

我正在尝试使用我的 local.xml 文件(我在其中对布局进行所有更新)来删除嵌套在另一个块中的块。我可以通过 <remove> 标记或使用 unsetChild 方法轻松删除块,但我似乎无法删除嵌套在另一个块中的块。

这是我要删除的代码行(位于 customer.xml 文件中)。特别是,它是名为“customer_account_dashboard_newsletter”的块

<customer_account_index translate="label">
        <label>Customer My Account Dashboard</label>
        <update handle="customer_account"/>
        <!-- Mage_Customer -->
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </reference>
        <reference name="my.account.wrapper">
            <block type="customer/account_dashboard" name="customer_account_dashboard" template="customer/account/dashboard.phtml">
                <block type="customer/account_dashboard_hello" name="customer_account_dashboard_hello" as="hello" template="customer/account/dashboard/hello.phtml"/>
                <block type="core/template" name="customer_account_dashboard_top" as="top" />
                <block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="customer/account/dashboard/info.phtml"/>
                <block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>
                <block type="customer/account_dashboard_address" name="customer_account_dashboard_address" as="address" template="customer/account/dashboard/address.phtml"/>
                <block type="core/template" name="customer_account_dashboard_info1" as="info1" />
                <block type="core/template" name="customer_account_dashboard_info2" as="info2" />
            </block>
        </reference>

    </customer_account_index>

我意识到这现在不起作用,但这是我的起点(位于我的 local.xml 文件中):

<customer_account_index>
    <reference name="my.account.wrapper">
            <action method="unsetChild"><name>customer_account_dashboard_newsletter</name></action>
    </reference>
</customer_account_index>

有什么想法吗?谢谢你。

4

4 回答 4

1

我认为您引用了错误的块。您必须引用要删除的块的父块。您正在引用父级的父级块。

<customer_account_index>
  <reference name="customer_account_dashboard">
    <action method="unsetChild"><name>customer_account_dashboard_newsletter</name></action>
  </reference>
</customer_account_index>
于 2010-07-14T14:21:01.220 回答
1

要取消设置另一个块内的块,您必须嵌套引用。例如:

<catalog_product_view>
    <reference name="content">
        <reference name="product.info">
            <action method="unsetChild"><name>addtocart</name></action>
        </reference>
    </reference>
</catalog_product_view>

此外,有时系统无法识别块名称,因此您必须在操作中使用别名。

于 2012-05-18T10:25:14.550 回答
0

通常,如果要删除嵌套块,还应该将引用嵌套在 中local.xml,在您的情况下,正确的语法是:

<customer_account_index>
    <reference name="my.account.wrapper">
        <reference name="customer_account_dashboard">
            <remove name="customer_account_dashboard_newsletter" />
        </reference>
    </reference>
</customer_account_index>

但我注意到以下行customer.xml

<block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>

没有显示要删除的块的效果。但是该块被添加到customer/account/dashboard/info.phtml模板中,该模板包含在上一行中 customer.xml

<block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="customer/account/dashboard/info.phtml"/>

如果您复制customer/account/dashboard/info.phtml到您的主题,您可以删除在仪表板上显示时事通讯块的代码:

<?php if( $this->isNewsletterEnabled() ): ?>
于 2014-03-01T11:35:15.227 回答
0

要从客户仪表板中删除时事通讯块,您必须修改文件

应用程序/前端/您的模板/模板/客户/帐户/仪表板/info.phtml

并删除这段代码

<?php if( $this->isNewsletterEnabled() ): ?>
<div class="col-2">
    <div class="box">
        <div class="box-title">
            <h3><?php echo $this->__('Newsletters') ?></h3>
            <a href="<?php echo $this->getUrl('newsletter/manage') ?>"><?php echo $this->__('Edit') ?></a>
        </div>
        <div class="box-content">
            <p>
                <?php if( $this->getIsSubscribed() ): ?>
                    <?php echo $this->__("You are currently subscribed to 'General Subscription'.") ?>
                <?php else: ?>
                    <?php echo $this->__('You are currently not subscribed to any newsletter.') ?>
                <?php endif; ?>
            </p>
        </div>
    </div>
    <?php /* Extensions placeholder */ ?>
    <?php echo $this->getChildHtml('customer.account.dashboard.info.extra')?>
</div>
<?php endif; ?>
于 2014-04-24T18:54:06.037 回答