2

This is my code:

$invoice = Mage::getModel('sales/order_invoice')->load($invoice_id)
$block = $this->getLayout()
        ->createBlock('mynamespace_mymodule/pdf_invoice')
        ->setData('invoice', $invoice)
        ->setTemplate('mynamespace_mymodule/pdf/invoice.phtml');
var_dump($block->toHtml());   

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:

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

2 Answers 2

6

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.

1
0

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 you have read our privacy policy.

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