Удаление блока, вложенного в блок, через файл local.xml - PullRequest
3 голосов
/ 13 июля 2010

Я пытаюсь использовать мой файл local.xml (где я делаю все свои обновления для макета), чтобы удалить блок, вложенный в другой блок. Я могу легко удалить блок с помощью тега или с помощью метода 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 ]

1 голос
/ 18 мая 2012

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

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

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

1 голос
/ 14 июля 2010

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

<customer_account_index>
  <reference name="customer_account_dashboard">
    <action method="unsetChild"><name>customer_account_dashboard_newsletter</name></action>
  </reference>
</customer_account_index>
0 голосов
/ 24 апреля 2014

Чтобы удалить блок 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; ?>
0 голосов
/ 01 марта 2014

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