开发者

Magento local.xml layout file - overriding <remove name="left"/>

开发者 https://www.devze.com 2023-02-02 07:28 出处:网络
Is there any way to override, or re-add something that was removed via it\'s xml layout, using local.xml?

Is there any way to override, or re-add something that was removed via it's xml layout, using local.xml?

I've made a theme that's all based on one page layout, 2columns-left. But a lot of pages, such as the sitemap, are set to use a 1column layout. So for example, in catalog.xml, we have:

<catalog_seo_sitemap translate="label">
    <label>Catalog Seo Sitemap (Common)</label>
    <remove name="right"/>
    <remove name="left"/>

    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
    </reference>
    <reference name="content">
        <block type="page/template_container" name="seo.sitemap.container" template="catalog/seo/sitemap/container.phtml">
            <block type="page/template_links" name="seo.sitemap.links" as="links" template="page/template/links.phtml"/>
            <block type="page/html_pager" name="seo.sitemap.pager.top" as="pager_top" template="page/html/pager.phtml"/>
            <block type="page/html_pager" name="seo.sitemap.pager.bottom" as="pager_bottom" template="page/html/pager.phtml"/>
        </block>
    </reference>
</catalog_seo_sitemap>

And in my local.xml, I can override the root template to use by adding:

<catalog_seo_sitemap>
<reference name="root">
    <action meth开发者_StackOverflowod="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
</catalog_seo_sitemap>

So it's now showing the sitemap in a 2column left layout. But there's nothing in the left column, as the < remove name="left" /> has removed it. I hate that I have to override this whole catalog.xml just to remove that, as it's a pain then when they update to a new version, I need to update all these extra layout files too.

So, is there any way to fix that using my local.xml? I think for the default Magento themes, they should have everything set to use the 3column layout, as that way you're free to remove whatever you don't need, but it's all there by default, so all changes can be done in the local.xml file.


Out of the box there's no way to unremove a layout block that's been removed by a previous call to <remove />. '

However, there's enough eventing in the Layout system that you can implement this yourself. And by "yourself", I mean I've created an experimental extension that adds a <unremove /> tag to the XML Layout system's grammer.


This has been asked before but no conclusion was reached. You can create a replacement block in your local.xml but there is no guarantee the child blocks added to it will be done so after your local changes.

<catalog_seo_sitemap>
    <reference name="root">
        <action method="setTemplate"><template>page/2columns-left.phtml</template></action>

        <block type="core/text_list" name="left" as="left" translate="label">
            <label>Left Column</label>
        </block> <!-- Copied from page.xml -->

        <block type="core/text_list" name="right" as="right" translate="label">
            <label>Right Column</label>
        </block> <!-- Copied from page.xml -->
    </reference>
</catalog_seo_sitemap>


I've managed to do this by just changing the blocks name when reading it. Seems that if you remove a block and re-add it with the same name the remove label will apply to all blocks of the same name. In my case it was removing a account navigation and adding to the header.

<remove name="customer_account_navigation" />  

<block type="customer/account_navigation" name="customer_account_nav" as="accountNavigation" template="customer/account/navigation.phtml">
0

精彩评论

暂无评论...
验证码 换一张
取 消