Удаление блока, вложенного в блок, через файл local.xml

Я пытаюсь использовать свой файл 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>

Есть предположения? Спасибо.


person user248173    schedule 12.07.2010    source источник


Ответы (4)


Я думаю, вы ссылаетесь на неправильный блок. Вы должны сослаться на родительский блок блока, который хотите удалить. Вы ссылаетесь на родительский блок родителя.

<customer_account_index>
  <reference name="customer_account_dashboard">
    <action method="unsetChild"><name>customer_account_dashboard_newsletter</name></action>
  </reference>
</customer_account_index>
person Thomas    schedule 14.07.2010

Чтобы отключить блок внутри другого блока, вы должны вложить ссылки. Например:

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

Также иногда система не распознает имя блока, поэтому в действии приходится использовать псевдоним.

person peterfh    schedule 18.05.2012

В общем, если вы хотите удалить вложенный блок, вы также должны вложить ссылки в 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() ): ?>
person KoviNET    schedule 01.03.2014

Чтобы удалить блок новостей из Личного кабинета клиента, вам необходимо изменить файл

приложение/внешний интерфейс/вашшаблон/шаблон/клиент/аккаунт/приборная панель/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; ?>
person lavb    schedule 24.04.2014