Reputation: 1759
I am trying to troubleshoot an issue where the output of my block is an empty string.
I traced it down to the point where I could see PHP statements being evaluated in the template file, but inside toHtml()
of class Mage_Core_Block_Abstract
, $html = $this->_toHtml();
assigns empty string to $html
.
I dig it further, and found that inside fetchView()
, $html = ob_get_clean();
assigns empty string to it, even when the template was included above this line, and I could see it evaluating with the use of debugger.
From here I am clueless on how to debug this, may be I am missing something wrong in my module (I am a beginner in Magento).
Here is the concerned code from the module:
app/code/local/AnattaDesign/AbandonedCarts/etc/config.xml
<config>
<global>
<blocks>
<anattadesign_abandonedcarts>
<class>AnattaDesign_AbandonedCarts_Block</class>
</anattadesign_abandonedcarts>
</blocks>
</global>
<adminhtml>
<layout>
<updates>
<anattadesign_abandonedcarts>
<file>layout.xml</file>
</anattadesign_abandonedcarts>
</updates>
</layout>
</adminhtml>
app/design/adminhtml/base/default/layout/layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<adminhtml_dashboard_index>
<reference name="head">
<action method="addCss">
<stylesheet>anattadesign/abandonedcarts/css/style.css</stylesheet>
</action>
<action method="addJs">
<script>anattadesign/abandonedcarts/zepto.js</script>
</action>
<action method="addJs">
<script>anattadesign/abandonedcarts/adminhack.js</script>
</action>
</reference>
</adminhtml_dashboard_index>
</layout>
app/code/local/AnattaDesign/AbandonedCarts/controllers/WidgetController.php
<?php
class AnattaDesign_AbandonedCarts_WidgetController extends Mage_Adminhtml_Controller_Action {
public function indexAction() {
echo "index action of widget controller";
die();
}
public function renderAction() {
$html = $this->getLayout()->createBlock( 'anattadesign_abandonedcarts/widget', 'root' )->setTemplate( 'anattadesign/abandonedcarts/widget.phtml' )->toHtml();
$this->getResponse()->setBody( $html );
die();
}
}
app/code/local/AnattaDesign/AbandonedCarts/Block/Widget.php
<?php
class AnattaDesign_AbandonedCarts_Block_Widget extends Mage_Core_Block_Template {
}
I am running this by an admin controller and making the renderAction()
fire.
Upvotes: 1
Views: 3220
Reputation: 17656
Remove the die() in method renderAction()
class AnattaDesign_AbandonedCarts_WidgetController extends Mage_Adminhtml_Controller_Action {
....
public function renderAction() {
$html = $this->getLayout()->createBlock( 'anattadesign_abandonedcarts/widget')
->setTemplate( 'coming.phtml' )
->toHtml();
$this->getResponse()->setBody( $html );
}
}
Upvotes: 5