douheng8629
douheng8629
采纳率100%
2015-12-08 15:37

Magento Block不工作 - 1.9.2.2

  • magento
  • module
  • php
  • block
已采纳

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 dpi74187 6年前

    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(); ?>
    
    点赞 评论 复制链接分享