dth42345 2010-12-02 15:57
浏览 31
已采纳

page.xml中定义的块不会呈现

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

  • 写回答

1条回答 默认 最新

  • duanpa5237 2010-12-02 16:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持