phpmagentoenterprisemage

Magento child html -- get parent caller


I am in the template file price.phtml. I would like to have some line of code that looks at the parent that is calling the block and do some behavior based on that. Essentially if the parent is a catalog list page, I want a from: tag to be added to the price. If the parent is configurable.phtml, I want to simply display the price as normal.

I already have the code to add the from: to the price but I need the if statement to tell what the parent caller is.

I have seen something like ::parent before when perusing Mage files, but I don't know if that is applicable here...

Thanks!


Solution

  • YOu can get reference to a block's parent block from a phtml by calling

    $parent = $this->getParentBlock();
    

    The calls to parent::someMethod have nothing to do with blocks, or with Magento. They're PHP constructs, used to indicate you want to call a method on the parent class.