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 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错