Domanda

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?

È stato utile?

Soluzione

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>

Altri suggerimenti

it should be

<reference name="header">
     <block type="core/template" name="textblock" template="page/html/textblock.phtml"/>
</reference>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top