I've recently started using the local.xml
as my playground for layouts. Before I had my doubts using it because of…reasons.
I got to see it's advantages, but I hit a brick wall now.
In the default catalog.xml
layout file there is a certain block (name not important). Using the layout.xml
I added a generic child block to it where I want to place other blocks.
<reference name="not.important">
<block type="core/text_list" name="extra.left.menu" as="extra" />
</reference>
So far so good.
But now, I have one extension that should add child block to the one declared above.
If I add this new block using local.xml
it works nicely.
<block type="core/text_list" name="extra.left.menu" as="extra">
<block type="myextension/some_block" template="some/template.phtml" as="some_name" name="some_name" />
</block>
But I don't want to do it via local.xml
because this new extension might be disabled in the future. If I do it via local.xml
and disable the extension it will flood my log files because the block does not exist anymore.
So in my extension layout file I add this:
<reference name="extra.left.menu">
<block type="myextension/some_block" template="some/template.phtml" as="some_name" name="some_name" />
</reference>
But This way it does not work. I feel this happens because the local.xml
file is loaded last, and I cannot add a module dependency so my extension layout file would be loaded after layout.xml
.
How should I tackle this? Did I get something wrong?
Or if I want it like this I have to use the "good old way" of cloning catalog.xml
in my theme and adding this new block in the catalog.xml
of my theme?
Best Answer
When rendering the layout in Magento a few steps happen:
So why isn't your example working? This is because the module XML file is loaded before the local.xml file. What happens is that the system first tries to add a block to a reference (to a block) which doesn't exist yet.
To solve te issue: You can use an update, updates get placed before the handles they are called in.
And in your other module file add the block like your did.