Magento – How to pass a variable from a.phtml Block to its parent block

custom blocktemplate

I've created a child block and inside there is a counter.
Now I need that value from the counter but the output is/shall before my block.

Is that possible?

It shall look like this:

html
 output the value of my counter
 childBlock (inside that block I will retrieve my counter value)

Best Answer

You can get childblock and pass parameters to it.

So in the parent before the getChildHtml('childBlock') function use echo $this->getChild('childBlock')->setCounter(123)->toHtml();

Related Topic