I'm probably thinking about this the wrong way, but I have two blocks and one is the child of the other. In the parent's template file, I'm calling getChildHtml() and rendering the child block that way.
However, before rendering the child block, I'd like to be able to check first if a certain condition is true for the child block. Is there a way for it to return false/true, and for the parent block to check that?
(Answer would preferably be particular to the above scenario rather than suggesting a completely different approach, though I'm always happy to hear thoughts)
1 Answer 1
you can get access to the child block instance using $child = $this->getChildBlock('child_name_here');
So you can add this method into the child block class:
public function isItTrue($paramsIfNeeded)
{
return true; //or false. or whatever.
}
Now you can check if ($child->getIsItTrue($oaramsIfNeeded)) {....}
-
That's awesome -- I feel like my understanding of Magento just increased exponentionally haha. Thank you!brackfost– brackfost2018年12月18日 13:43:12 +00:00Commented Dec 18, 2018 at 13:43
-
I actually couldn't get getChild() to work in the template file, but getChildBlock() worked.brackfost– brackfost2018年12月18日 14:21:32 +00:00Commented Dec 18, 2018 at 14:21
-
@BrockfastCowboy. You might be rightMarius– Marius2018年12月18日 14:26:57 +00:00Commented Dec 18, 2018 at 14:26
-
1Might be? : ) (Thanks again)brackfost– brackfost2018年12月18日 14:51:21 +00:00Commented Dec 18, 2018 at 14:51