1

I am in head.phtml file and need to change the content of <?php echo $this->getChildHtml() ?> as there is no name inside getChildHtml(), i don't know thow to look in layout file then.

I almost opened all files in active theme but didn't find the google script that i want to update.

I found a similar question here same question but not understood how to trace.

1

So basically, when there's no block name passed as an argument, all the child blocks get renderer.

If you check app/code/core/Mage/Core/Block/Abstract.php you'll find the following details of this method:

public function getChildHtml($name = '', $useCache = true, $sorted = false)
{
    if ($name === '') {
        if ($sorted) {
            $children = array();
            foreach ($this->getSortedChildren() as $childName) {
                $children[$childName] = $this->getLayout()->getBlock($childName);
            }
        } else {
            $children = $this->getChild();
        }
        $out = '';
        foreach ($children as $child) {
            $out .= $this->_getChildHtml($child->getBlockAlias(), $useCache);
        }
        return $out;
    } else {
        return $this->_getChildHtml($name, $useCache);
    }
}

So if you wanna find out the list of blocks rendered you can modify the following piece of code:

    $out = '';
    foreach ($children as $child) {
        $out .= $this->_getChildHtml($child->getBlockAlias(), $useCache);
    }
    return $out;

And add the following to it:

    $out = '';
    foreach ($children as $child) {
        if ($this->getNameInLayout() == "head") {
            Mage::log($child->getBlockAlias());
        }
        $out .= $this->_getChildHtml($child->getBlockAlias(), $useCache);
    }
    return $out;

Thanks to this modification, you'll be able to find the list of all block aliases rendered in your head.phtml by looking at the var/log/system.log file (ensure logging is enabled)

  • Thank you for sharing your knowledge.I did what you suggested, in system.log i found 2017-04-28T05:38:01+00:00 DEBUG (7): js_cookies 2017-04-28T05:38:01+00:00 DEBUG (7): optional_zip_countries 2017-04-28T05:38:01+00:00 DEBUG (7): google_analytics – inrsaurabh Apr 28 '17 at 5:44
  • but the script which i am searching is coming from a module phtml file , which i just found. – inrsaurabh Apr 28 '17 at 5:46
  • Still i want to learn the method you suggested to find the path . Can you please help. – inrsaurabh Apr 28 '17 at 5:47
  • @SaurabhRanjan if you want to find the template path then just enable the template hints and check the templates in the head. – Raphael at Digital Pianism Apr 28 '17 at 6:31
  • i know template path hint . "To find the list of all block aliases" by using above function. As you suggested – inrsaurabh Apr 28 '17 at 6:34

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.