2

With my local.xml, I am already able to add CSS and JS files. Now I want to add an .phtml file to the rwd/default/layout/page.xml file, but it won't work.

In the page.xml file, there is a block with the name 'header'. I have made a reference to it in my own local.xml file like this:

    <reference name="header">
         <block type="page/html_textblock" name="textblock" template="page/html/textblock.phtml"/>
    </reference>

The block inside the reference points to the textblock.phtml file, which only contains the sentence:

hey there

How do I make this sentence show on the page.xml, without altering the file?

3

Well, there's two problems here in my opinion.

First, referencing a block won't necessarily display it.

It depends on the template of the block you're referencing.

In your case header.phtml does not automatically renders all its child block via the following code:

echo $this->getChildHtml();

Indeed, this template renders the block explicitely by passing the block name as an argument to the code above.

Thus if you want to display your block you will have to modify the header.phtml and add the following code to it:

echo $this->getChildHtml('textblock');

On top of that I don't think there's any page/html_textblock block type out of the box in Magento.

If you want to display the content of a template you can do the following:

<block type="core/template" name="textblock" template="page/html/textblock.phtml"/>

If you just want to display some hardcoded text you can do the following:

<block type="core/text" name="textblock">
    <action method="setText">
        <text><![CDATA[Hey There]]></text>
    </action>
</block>
4
  • It worked very well, but is there also a way where I don't override the header.phtml file? – Maarten Wolfsen Aug 30 '16 at 9:46
  • 1
    @MaartenWolfsen unfortunately if you're using the default header.phtml file and absolutely want to add that block to the header no there's no way because as I said, the default header template does not render all its child block automatically – Raphael at Digital Pianism Aug 30 '16 at 9:47
  • Hmm, okay, well, thanks for your help anyway! Helped me alot – Maarten Wolfsen Aug 30 '16 at 9:48
  • 1
    @MaartenWolfsen not a problem. Feel free to mark your question as answered so it will benefit for others ;) – Raphael at Digital Pianism Aug 30 '16 at 9:48
0

it should be

<reference name="header">
     <block type="core/template" name="textblock" template="page/html/textblock.phtml"/>
</reference>
4
  • why core/template, if I may ask? – Maarten Wolfsen Aug 30 '16 at 9:41
  • Also, it does not work yet :/ – Maarten Wolfsen Aug 30 '16 at 9:42
  • for that you need to understand what is block type in magento and if I write block/template it means it call Mage_Core_Block_Template class – Murtuza Zabuawala Aug 30 '16 at 9:44
  • Also Add this line in your theme header.phtml file echo $this->getChildHtml('textblock'); – Murtuza Zabuawala Aug 30 '16 at 9:45

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.