I don't know why but i get this error: Call to a member function setData() on boolean in observer line 22, and this line is: $head->setData('title', $metaTitle);


class Namespace_Category_Model_Observer
    public function setMetaTitle(Varien_Event_Observer $observer)
        $head = $observer->getLayout()->getBlock('head');
        $metaTitle = Mage::registry('current_category')->getMeta_title();
        Mage::log($metaTitle); //I get the right value
        if (Mage::registry('current_category')) {
            $head->setData('title', $metaTitle); //line 22

The event that i used is: <controller_action_layout_load_before>

EDIT: I just realized that i can't return a head block, $head return nothing !

I tryed also Mage::app()->getLayout()->getBlock('head') but it doesn't work

  • Make some debug on it... It seems like 'head' block it's not found on layout structure. Maybe you'll find some informations in '$observer->getLayout()' output. Oct 18, 2017 at 12:06
  • effectively, i can't get my head block, $head return nothing
    – PЯINCƎ
    Oct 18, 2017 at 12:36
  • That's what I'm talking about... your $head variable is null. Try to debug it step by step. First of all make sure that $observer->getLayout() is an object and it's not null. If it's not null, try to find some informations about block names included. You can render that output with a var_dump or by using xdebug. Oct 18, 2017 at 13:08
  • yes i have do that but some data and not a head one
    – PЯINCƎ
    Oct 18, 2017 at 13:25

2 Answers 2


Your getBlock('head') returns false, so setData() cant work.

Please try controller_action_layout_render_before_catalog_category_view event and an observer like ...

public function setMetaTitle(Varien_Event_Observer $observer)
    $category = Mage::registry('current_category');
    $head = Mage::app()->getLayout()->getBlock('head');
    if ($head) {
        $head->setData('title', 'new meta title');
        $category->setData('name', 'new category title');
  • It's doesn't work with this event @sv3n, it loads very long time and the category page dones't display
    – PЯINCƎ
    Oct 18, 2017 at 13:41
  • @Prince Strange. Flushed chache after chaning event? Tested this on fresh magento.
    – sv3n
    Oct 18, 2017 at 13:43
  • Yes, it's verry Strange, of course I flush a cache every time when i do some update
    – PЯINCƎ
    Oct 18, 2017 at 13:46
  • Sorry @sv3n i don't know why but it works now, YES YES, thanks Can you tel me how you found this event and why it does't for my event, because i find this a litle strange, (to my knowledge the controller_action_layout_load_before loads all the layout before rendering)
    – PЯINCƎ
    Oct 18, 2017 at 13:54
  • @Prince for finding events either add logging to dispatchEvent method in App.php or use pulsestorm.net/commerce-bug (worth its money!) Your layout_load_before events is triggered bit to early, you need one after load, but befor rendering.
    – sv3n
    Oct 18, 2017 at 14:20

If you want to change layout using observer you can change your event to


Then you can get your head block in observer method from below code

$controller   = $observer->getAction();
$layout       = $controller->getLayout();
$head = $layout->getBlock('head');
  • the event is not a good one, he bug my browser
    – PЯINCƎ
    Oct 18, 2017 at 13:24

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.