2

I work with blog extension that has it's own layout file. I need to insert my own block inside blog post.

My problem is that if I try to reference post block in my own xml file it doesn't work and getChildHtml returns nothing.

Here is my xml code that adds my block:

<blog_post_view>
...
<reference name="post">
    <block type="core/text" name="test">
        <action method="setText"><text>Hola!</text></action>
    </block>
</reference>
...
</blog_post_view>

If I add this block directly into extension's layout file:

<blog_post_view>
...
<reference name="content">
...
    <block type="blog/post" name="post" template="blog/post.phtml">
        <block type="core/text" name="test">
            <action method="setText"><text>Hola!</text></action>
        </block>
    </block>
</reference>
...
</blog_post_view>

It works properly, getChildHtml returns text block content.

If I add <remove name="post" /> to my own xml it removes post, so my xml file works and the name is correct.

What else can prevent reference from working?

I'm using Magento CE 1.9.1.

1 Answer 1

2

Make sure you module depends on the blog module you are using.
So your app/etc/modules/[Namespace]_[Module].xml must contain this:

<?xml version="1.0"?>
<config>
    <modules>
        <[Namespace]_[Module]>
            <codePool>local</codePool><!-- or community -->
            <active>true</active>
            <depends>
                <[Whatever]_Blog />
            </depends>
        </[Namespace]_[Module]>
    </modules>
</config>

this way, your layout file is loaded after the original one.
It works for remove directives because they are parsed differently.

1
  • Thanks, that works. I created block programmatically in template file, but layout way is much cleaner.
    – nevermourn
    Mar 31, 2015 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.