Ventus
Ventus

Reputation: 2550

Block defined in page.xml do not render

I have made a custom block in Magento that contains some JS. I want to have it placed right after <head> in output HTML. Block looks like this:


<?php if($this->isHomePage()): ?>
<script language='JavaScript1.1' type='text/javascript'>ns_loadingtime1=(new Date()).getTime()</script>
<?php endif ?>

In a page.xml file of my template I have this:


(...)
<block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">
            <block type="baobaz_tags/widget_nedstattag_metadata" name="baobaz_nedstattag_head" as="nedstattagHead" before="head" template="baobaz/tags/widget/nedstattag/homepage/meta.phtml" />
            <block type="page/html_head" name="head" as="head">

In output HTML my custom block (baobaz_nedstattag_head) don't exists. Do you know what can I do to render it as I wish?

EDIT Thanks to comment of Fabrizio I was able to make it right. Because in his approach I was getting double entry of my block. So I left the page.xml as it's written above and I have added to 1column.phtml $this->getChildHtml('nedstattagHead') before calling head block

Upvotes: 0

Views: 265

Answers (1)

Fabrizio D&#39;Ammassa
Fabrizio D&#39;Ammassa

Reputation: 4769

You can try to move the block definition inside the head block definition:

<block type="page/html_head" name="head" as="head">
     <block type="baobaz_tags/widget_nedstattag_metadata" name="baobaz_nedstattag_head" as="nedstattagHead" template="baobaz/tags/widget/nedstattag/homepage/meta.phtml"  before="-" />

 ... missing code of head block definition ...
</block>

Make sure you add the echo $this->getChildHtml('nedstattagHead') in the page/html/head.phtml file.

Upvotes: 1

Related Questions