Is there any way I can check if a block is displayed on the current page?
I have a block my.banner
with simple image. This block is added to the left sidebar on many different types of pages, e.g. on category pages, on custom CMS pages etc.
<default>
<reference name="header">
<block type="mymodule/header" name="my_header" template="header.phtml" />
</reference>
</default>
<cms_page>
<reference name="left">
<block type="mymodule/banner" name="my.banner" template="banner.phtml" />
</reference>
</cms_page>
<catalog_category_default>
<reference name="left">
<block type="mymodule/banner" name="my.banner" template="banner.phtml" />
</reference>
</catalog_category_default>
...
Then, in another block my_header
in the header I need to programmatically check if my.banner
block will be actually displayed on the current page. If it's not displayed, then in the header I need to display additional info for customers.
I can check if the my.banner
exists in the layout:
$block = $this->getLayout()->getBlock('my.banner');
if ($block !== false)
{
//...banner exists
}
But this is not a solution, because the problem is that admin can any time disable the left sidebar (e.g. on selected category page). And if the left sidebar was removed, then my.banner
will not be displayed even if it's added to the sidebar in layout.
So is there any way I can check if
my.banner
block will be actually rendered and displayed on the page?And if it's possible in Magento 1, what is equivalent in Magento 2?