Magento Shortcode CMS block not working on product pages

China☆狼群 提交于 2020-01-05 18:40:29

问题


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.



来源:https://stackoverflow.com/questions/16386902/magento-shortcode-cms-block-not-working-on-product-pages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!