douheng8629 2015-12-08 15:37 采纳率: 100%
浏览 45
已采纳

Magento Block不工作 - 1.9.2.2

I've created a custom extension and I'm trying to render a custom block. However, I see nothing.

My code is as follows;

app/code/local/Gdaze/Megamenu/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gdaze_Megamenu>
            <version>0.1.0</version>
        </Gdaze_Megamenu>
    </modules>

    <global>
        <blocks>
            <megamenu>
                <class>Gdaze_Megamenu_Block</class>
            </megamenu>
        </blocks>
    </global>
</config>

app/code/local/Gdaze/Megamenu/Block/Customblock.php

<?php
  class Gdaze_Megamenu_Block_Customblock extends Mage_Core_Block_Template
  {

  }
?>

app/design/frontend/rwd/site/gdaze/megamenu.phtml

<?php echo "Works"; ?>

My method of calling the block.

<?php $this->getLayout()->createBlock('megamenu/customblock')->setTemplate('gdaze/megamenu.phtml')->toHtml(); ?>

I don't really understand what's happening here. I've tried whitelisting the block (a new problem since 1.9.2.2) by adding megamenu/customblock. I've googled the cr*p out of this, but everything suggested just doesn't seem to work. Am I missing something really obvious? Any ideas?

  • 写回答

1条回答 默认 最新

  • dpi74187 2015-12-09 09:41
    关注

    Turns out, I was a bit of an idiot. In my calling statement, I neglected to echo the results.

    <?php ***echo*** $this->getLayout()->createBlock('megamenu/customblock')->setTemplate('gdaze/megamenu.phtml')->toHtml(); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?