Nathaniel Wendt Nathaniel Wendt - 1 year ago 109
PHP Question

Magento child html -- get parent caller

I am in the template file

. 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
tag to be added to the price. If the parent is
, I want to simply display the price as normal.

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

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


Answer Source

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.