1

I need to append the before attribute to a block via a layout update reference call.

This is my local.xml file:

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="content">
            <block type="page/html_wrapper" name="content.footer" as="contentFooter" translate="label" after="-">
                <label>Content Footer</label>
                <action method="setElementId"><value>content-footer</value></action>
                <action method="setElementClass"><value>clear</value></action>
            </block>
        </reference>
    </default>
    <catalog_category_default>
        <reference name="breadcrumbs.container">
            <action method="unsetChild"><name>category.title</name></action>
        </reference>
        <reference name="content">
            <block type="catalog/category_view" name="category.title" template="catalog/category/title.phtml" before="content.footer"/>
        </reference>
    </catalog_category_default>
</layout>

My problem is, on the content block I create a content.footer block that you can assign widgets to in admin. I use after="-" on the content.footer block so in my mind, should put it ALWAYS at the bottom of the content block but this is not the case.

When you view a catalog category and it inserts the category.products block in to the content block, it displays underneath the content.footer block. The only way to make it work is if I redefine it in my local.xml and include all the child blocks in category.products, and set before before="content.footer".

So I thought why can't I use a reference to category.products in the catalog_category_default layout and set the block's before attribute, I tried the following:

<reference name="category.products">
    <action method="setBefore"><value>content.footer</value></action>
</reference>

Which had no affect.

I also noticed the setAttribute() function in Mage_Core_Block_Abstract which saw it's just a wrapper for setData() but thought I would try it anyway, still nothing:

<reference name="category.products">
    <action method="setAttribute"><key>before</key><value>content.footer</value></action>
</reference>

Is it possible to do what I want? Does before/after only apply to blocks in the same reference?

1 Answer 1

5

Layout updates are processed in order of layout update handles. Your block is being added last to content but only for the default LUH. Other handles (catalog_product_view, catalog_category_layered, etc) are processed after this handle.

If you truly need a content footer everywhere and want to make sure that it is the last thing inside of the content div, you should add your block to the root node in the default handle and customize the root templates (directly under page/, e.g. page/1column.phtml) by adding a getChildHtml('your.block') call after the getChildHtml('content') call. This will ensure that your block is always immediately at the end of the content blocks.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ben! I thought this may be the case. Seeing as I only really need it in the catalog category pages I will remove it from the default layout and update the category layouts when I do my other updates so I can force it to the bottom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.