简体   繁体   中英

Display Static Block in Magento PHTML File

I'm using the following code in my 2columns-right.phtml file to call a stack block made in the Mangento admin panel onto a product page:

<?php echo $this->getChildHtml('right') ?> <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('recipes')->toHTML(); ?>

I also have this code in my catalog.xml:

<reference name="right">
<block type="cms/block" name="recipes">
<action method="setBlockId"><block_id>recipes</block_id></action>
</block>
</reference>

Nothing is rendering on to the page. I've echoed some dummy text and that's rendered in the right spot so I know have the right .phtml file, but I am getting no sign of the block.

create local.xml under app/design/frontend/your package/your template/layout/

and out the below code

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="right">
            <block type="cms/block" name="recipes" before="cart_sidebar"  output="toHtml">
                <!--
                    The content of this block is taken from the database by its block_id.
                    You can manage it in admin CMS -> Static Blocks
                -->
                <action method="setBlockId"><block_id>recipes</block_id></action>
            </block>
        </reference>
    </default>

also check cms block is exiting or not in admin and also check store select or not .If multi store exit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM