1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Use CMS blocks inside product attributes

Discussion in 'Programming/Internet' started by sv3n, Oct 8, 2018.

  1. sv3n

    sv3n Guest

    I want to use CMS blocks inside product attributes, eg in description and short description.

    • inside product description I've added {{block id="test1"}}.
    • i have two observer
      • catalog_product_collection_load_after for collections
      • catalog_controller_product_view for products

    My data helper looks like ...

    use Magento\Cms\Model\Template\FilterProvider
    public function __construct(Context $context, FilterProvider $filterProvider)
    $this->filterProvider = $filterProvider;

    public function insertCmsBlocks(Product $product, string $attributeCode, string $attributeValue): string
    # ...
    // get cms blocks
    $attributeValue = $this->filterProvider->getBlockFilter()->filter($attributeValue);
    # ...

    $product->setData($attributeCode, $attributeValue);

    This works w/o any problems for collections ...


    ... but for product page content isnt rendered:


    Debugging $this->filterProvider->getBlockFilter()->filter($attributeValue) looks also OK:


    Any ideas whats wrong with this code?

    Login To add answer/comment

Share This Page