This is my code:

$invoice = Mage::getModel('sales/order_invoice')->load($invoice_id)
$block = $this->getLayout()
        ->setData('invoice', $invoice)

The result of the var_dump is empty. Smth I am missing. What should I have to check ? thx

This is the xml from layout:

        <reference name="content">
            <block type="mynamespace_mymodule/pdf_invoice" template ="mynamespace_mymodule/pdf_invoice.phtml" output="toHtml" name="email_invoice_pdf"/>

2 Answers 2


The most common reasons for an empty return value of toHtml() are:

  • module output is disabled for Mynamespace_Mymodule in System > Configuration > Advanced > Disable Module Output
  • the template is behind a symlink and symlinks are not allowed in System > Configuration > Developer > Template

Update: Having a closer look at your code, you are referencing two different blocks in XML and PHP, mynamespace_mymodule/adminhtml_pdf_invoice/mynamespace_mymodule/pdf_invoice. But I don't think that is the problem, because you would get an error message if the block class was missing. Also if you use createBlock, nothing has to be defined in the XML.


In my case empty string was related to the need to specify template in appropriate block.

For example "$this->setTemplate('Acidgreen_BlogPage::page/view/list.phtml')" in block constructor.

Because it was specified in XML and it doesn't work when trying to get html with ajax.

/** @var \Magento\Framework\View\Layout $layout */
$layout = $this->_view->getLayout();
/** @var \Acidgreen\BlogPage\Block\Post\PostList\Posts $block */
$block = $layout->createBlock(\Acidgreen\BlogPage\Block\Post\PostList\Posts::class);

/** @var array $response */
$response = [
    'content' => $block->toHtml(),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.