Adding CMS Blocks to a Products, not programatically - Magento 2
-
23-01-2021 - |
Question
I would like to add additional information to specified products, we would like to use the block as a template where we would just need to add this block to the product content so it would appear without problem in the products we desire.
This is the block:
Here is the product content:
But it doesn't show up after the text we already have:
We would like this to not be programatically, so someone who doesn't have acces to the code, only to the magento website can manage to make all the changes needed.
Solution
Below extension might help you if you don't want to do it programmatically.
https://ecommerce.aheadworks.com/magento-2-extensions/custom-static-blocks/
However just in case if you want to do it programmatically, it can be done by below.
Navigate to: Magento_Catalog/layout/catalog_product_view.xml and call the block there as below
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.details">
<block class="Magento\Cms\Block\Block" name="product.extraproduct.tab" as="extraproduct.tab" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">extra product</argument>
<argument name="block_id" xsi:type="string">extra_product</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Flush the cache once done
php bin/magento cache:flush