Magento Shortcode CMS block not working on product

2019-08-12 17:04发布

问题:

I am attempting to add a CMS block on a Magento product page.

The shortcode which I am using is:

{{block type="cms/block" block_id="myproductblock"}}

The block shows up as text. It does not insert the CMS block. I have made sure that the WYSIWYG editor is disabled.

回答1:

I assume you want to add it to product.phtml

To do this, you need to edit the layout/catalog.xml

...
<catalog_product_view>
..
...
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
    <!-- start your code: -->
    <block type="cms/block" name="myproductblock" before="-">
        <action method="setBlockId"><block_id>myproductblock</block_id></action>
    </block>

Then inside your view.phtml you write:

<?php echo $this->getChildHtml("myproductblock") ?>

Where the "myproductblock" is the same as the name you specified inside the layout.xml

After this you have to clear the layout.xml cache and it should work :)


Why your code didn't work: Those .phtml files all are php-scripts.. the "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.



标签: magento block