2010-07-12 83 views
3

我正在嘗試使用我的local.xml文件(其中我執行了所有對佈局)的更新以刪除嵌套在另一個塊中的塊。可以通過<刪除>標籤或使用unsetChild方法輕鬆刪除塊,但我似乎無法刪除嵌套在另一個塊中的塊通過local.xml文件刪除嵌套在塊中的塊

以下是我嘗試刪除的代碼行(位於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> 

有什麼想法?謝謝。

回答

1

我想你是指的是錯誤的塊。您必須引用要刪除的塊的父塊。您正在引用父級的父級塊。

<customer_account_index> 
    <reference name="customer_account_dashboard"> 
    <action method="unsetChild"><name>customer_account_dashboard_newsletter</name></action> 
    </reference> 
</customer_account_index> 
+0

此該塊不工作。有沒有其他方法可以做到這一點? – jdhaar 2013-07-17 11:21:27

+0

也不適合我在Magento 1.8中工作。 – KoviNET 2014-03-01 11:13:52

1

要取消設置另一個塊內的塊,必須嵌套參考。例如:

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

此外,有時系統無法識別塊名稱,因此您必須在操作中使用別名。

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"/> 

不具有顯示要刪除的塊的效果。

<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()): ?> 
但塊內 customer/account/dashboard/info.phtml模板,這是在 customer.xml包括由前行,而不是添加
0

從客戶儀表盤刪除通訊塊,你必須修改文件

應用程序/前端/ 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; ?>