Get containing Area handle in block type controller.php
Permalink 1 user found helpful
I am creating a block type and am trying to display different data based on the Area that the block is contained in. To do this I need the Area handle. So my question is, how do I get the area handle from the controller.php file of my block type?
Thanks John, I gave it a shot and got this error message after placing it in my view() method in the controller.php file:
Fatal error: Cannot access protected property BlockView::$block
Any ideas?
Fatal error: Cannot access protected property BlockView::$block
Any ideas?
Maybe you can't do that from the controller.
But it sounds like you want it from the view anyway, which this should work:
But it sounds like you want it from the view anyway, which this should work:
$areaName = $this->block->getAreaHandle();
You sir are a genius! Thanks for the help!!
It might be worth noting here, as I was caught out by this, that this method will not work for Stacks, as the same area handle is always returned.
if ($this->block->isBlockInStack()) { $area_handle = $this->block->c->getStackName(); } else { $area_handle = $this->block->getAreaHandle(); }
Please let me know if that works :)
John