我正在尝试使用我的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>
有什么想法?谢谢。
答案 0 :(得分:1)
我认为你引用了错误的块。您必须引用要删除的块的父块。您正在引用父级的父块。
<customer_account_index>
<reference name="customer_account_dashboard">
<action method="unsetChild"><name>customer_account_dashboard_newsletter</name></action>
</reference>
</customer_account_index>
答案 1 :(得分:1)
要在另一个块中取消设置块,您必须嵌套引用。例如:
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<action method="unsetChild"><name>addtocart</name></action>
</reference>
</reference>
</catalog_product_view>
此外,有时系统无法识别块名称,因此您必须在操作中使用别名。
答案 2 :(得分: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() ): ?>
答案 3 :(得分:0)
要从Customer DashBoard中删除Newsletter块,您必须修改文件
应用程序/前端/ yourtemplate /模板/客户/帐户/仪表板/ 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; ?>