In Magento 1.9, I could test if a CMS Static Block was active with the following code:
if ( Mage::getModel('cms/block')->load('block_id')->getIsActive() == 1) {...}
How would I do the same in Magento 2? This is what I've tried so far:
$blockIsActive = $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('7')->getIsActive();
if ($blockisActive == 1){..}
Best Answer
If you use
Then there are not need to check block is active or not because of
Magento\Cms\Block\Block
's_toHtml()
function return content whenever the block is active[ by checkingif ($block->isActive()) {
]Check _toHtml() function of that class:
For logical reference,you can use below