I need to create a block from a cronjob that render products grid (yes I know it sound weird), and get the output html. To do so I created a custom block with template and tried to use it like this (reminder: from a cronjob):
$block = Mage::app()->getLayout()->createBlock('my_special_block') ->setTemplate('my_special_template.phtml'); Mage::log($block->toHtml());
This returned the html of a product grids with products in it, but they looked nothing like the actual site products. So I tried using this code in a controller, something like this:
$block = $this->getLayout()->createBlock('my_special_block') ->setTemplate('my_special_template.phtml'); echo $block->toHtml();
And indeed the html I get when going to the controller url is totally different than the one I got from the cron.
My guess is that when I get the layout in the cron, Magento don’t load all the layout updates or something like that. but I couldn’t find info in the docs of how to do it. Or maybe its a different problem?
Any solution would be appreciated, I just need to get my hands on the correct html from inside the cron.
Tried adding these lines before creating the block in the cronjob, but the html still looks different. :/
Mage::app()->setCurrentStore(0); $layout = Mage::app()->getLayout(); $layout->getUpdate()->addHandle('default')->load();