Using observer how to set catalog categories content Add CMS Block (category.description) programmatically
Programmatically set CMS block for catalog categories add CMS block:
<?php
echo $this->getLayout()
->createBlock(\Magento\Cms\Block\Block::class)
->setBlockId('my_cmsblock_identifier')
->toHtml();
?>
or
<referenceContainer name="content">
<block class="Magento\Cms\Block\Block" name="unick_block_name">
<arguments>
<argument name="block_id" xsi:type="string">my_cmsblock_identifier</argument>
</arguments>
</block>
</referenceContainer>
If any better way to set pls suggest me regard set cms block to category description.
How to include into my observer.
My observer:
<?php
namespace Zero\DescBlock\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class CollectionObserver implements ObserverInterface
{
protected $layerResolver;
public function __construct( \Magento\Catalog\Model\Layer\Resolver $layerResolver
) {
$this->layerResolver = $layerResolver;
}
public function execute(Observer $observer)
{
$layer = $this->layerResolver->get();
$activeFilters = $layer->getState()->getFilters();
foreach ($activeFilters as $filter)
{
$filterLabel = $filter->getLabel();
$filterValue = $filter->getValue();
}
}
}
Condition : Here my filterLabel is, apple and orange if filterLabel is apple i need to set cms block identifier my_apple if orange cms block identifier my_orange.
Any help thanks.