4

I have a new cron job collecting data, working with it and so on.
Now I want to send a mail with a template from inside that cron job.

But first I had to load/render my template file(s).

Therefore I have a new method:

private function generatePdf($name, $address, $vatId, $data)
{
    $layout = Mage::app()->getLayout();
    $block = $layout->createBlock('core/template', 'mymodule_mail')
        ->setTemplate('mail/default/html/layout.phtml');
    $grid = $block->setChild('product.item', $block);
    $html = $grid->toHtml();

    return $html;
}

But everytime I start and debug my cron job the $html variable is empty. Nothing. I can see that $block is from type Mage_Core_Block_Template and that the _template has the correct value. But I can't see any HTML-Code.

What am I missing here?

EDIT

Mage::getDesign()->setArea('frontend') //Area (frontend|adminhtml)
->setPackageName('mymodule') //Name of Package
->setTheme('default'); // Name of theme

That helps!

Now I have the problem that I don't know how to set a template for a child?

2

Looking at the code you posted, I think you created a block with name mymodule_mail that has a child with alias product.item, which contains an instance of the mymodule_mail block. Instead of referring to the original block, a new block should be created instead. Also, the $grid and $block variables are references to the same object.

You are probably looking for something like this:

private function generatePdf($name, $address, $vatId, $data)
{
    $layout = Mage::app()->getLayout();
    $block = $layout->createBlock('core/template', 'mymodule_mail')
        ->setTemplate('mail/default/html/layout.phtml');
    $itemBlock = $layout->createBlock('core/template', 'product.item')
        ->setTemplate('mail/default/html/layout/item.phtml');
    $block->setChild('product.item', $itemBlock);
    $html = $block->toHtml();

    return $html;
}

And to make sure item.phtml is shown, the following line should be added to layout.phtml at the desired location:

<?php echo $this->getChildHtml('product.item') ?>
| improve this answer | |
1

I would love to see @Tipo to post this answer he found. In case you see this, do it on your own and tell me, I'll delete my answer.

Solution:

Mage::getDesign()->setArea('frontend') //Area (frontend|adminhtml)
->setPackageName('mymodule') //Name of Package
->setTheme('default'); // Name of theme
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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