Magento – edit breadcrumb from block

To edit a breadcrumb from the block, you can simply do that :

class Adin_Sales_Block_Invoice_View extends Mage_Core_Block_Template

    private $_mainOrder;

    public function _prepareLayout()
        if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
            $breadcrumbs->addCrumb('All orders', array('label'=>$this->__('All my invoices'), 'title'=>$this->__('All my invoices'), 'link'=>$this->getUrl('sales/invoice/history')));
            $breadcrumbs->addCrumb('My order', array('label'=>$this->__('My invoices : order %s', $this->_mainOrder->getIncrementId()), 'title'=>$this->__('My invoices : order %s',$this->_mainOrder->getIncrementId()), ));
        return parent::_prepareLayout();

$_mainOrder is defined in the __contruct() function

Magento add block into cms page and add permissions

If you want to add a block into cms page, you just have to add this into its content

{{block type="adin_page/page_html_combos" name="combos" template="page/html/combos.phtml"}} 

Of course, don’t forget to create the block class app/code/local/Adin/Page/Block/Page/Html/Combos.php

class Adin_Page_Block_Page_Html_Combos extends Mage_Core_Block_Template

and the .phtml file

But when you want to render the page, nothing.
On the logs (system.log), you have : Security problem: adin_page/page_html_combos has not been whitelisted.
It’s a new feature since securoty Patch SUPEE-7405 and Magento CE, you have to add your block into whitelist. You can do it manually, in backoffice, System > Permissions > Blocks or do it programmatically :

$blockNames = array(
foreach ($blockNames as $blockName) {
    $whitelistBlock = Mage::getModel('admin/block')->load($blockName, 'block_name');
    $whitelistBlock->setData('block_name', $blockName);
    $whitelistBlock->setData('is_allowed', 1);

Magento – add something in the header section

If you need to add something in the header section of all your pages, you can go on your template and add it to the files 1column.phtml, 2columns-left.phtml, 2columns-right.phtml… You can, but you shouldn’t, it’s not a good practice.

Let’s see the content of one of this file

<?php echo $this->getChildHtml('head') ?>

You can see the section will be filled with all “head” child block, so let’s create one.

On your layout file (design/frontend/adin/default/layout/adin_page.xml), add the declaration of your new block

<layout version="0.1.0">
        <reference name="head" before="-">
            <block type="adin_page/headerstuff" name="headerstuff" as="headerstuff" template="page/html/headerstuff.phtml" />

Create the block class in app/code/local/Adin/Page/Block/Headerstuff.php

class Adin_Page_Block_Headerstuff extends Mage_Core_Block_Template
    public function _construct()

And create you template file app/design/frontend/adin/default/template/page/html/headerstuff.phtml

<!-- header my stuff to put in the header -->

Magento load template from controller

To load html content of a template inside a controller, for example for ajax response, you can do :

$block = $this->getLayout()->createBlock('adin_admin/adminhtml_scheduletcrender')->setTemplate('admin/scheduletcrender.phtml');
$block->assign(array('ateliers' => $ateliers));
$html = $block->toHtml();
$response = array('html' => $html);
//send response as json
$this->getResponse()->setHeader('Content-type', 'application/json');

Magento render cms/block with widgets

You create a cms static block (cms/block) and dynamise it with widget, here an example:

 <div class="confirmation">
        <img src="{{skin url='images/image-order.jpg'}}" alt="" />

You then render this block :

echo Mage::getModel('cms/block')

But the widget {{skin url=’images/image-order.jpg’}} is not executed and is display as {{skin url=’images/image-order.jpg’}}.

To execute the widget, you need to render as HTML a block and not a model

echo  Mage::app()->getLayout()->createBlock('cms/block')->setBlockId(self::confirmationCmsBlockName)->toHtml();