开发者

Magento - Add CMS Block to One Page

I have this code in a xml layout file:

<reference name="left">     
      <block type="blog/blog" name="left.blog.menu"  before="-">            
    <action method="setTemplate" ifconfig="blog/menu/left">
       <template>aw_blog/menu.phtml</template> 
    </action>
        <block type="blog/tags" name="blog_tags" />
      </block>
</reference>

I want to add a cms static block to the blog pages using this code:

<block type="cms/block" name="brand_list">
    <action method="setBlockId"><block_id>brand_list</block_id></action>
</block>

If I add it in directly after this line:

<reference name="left"> 

It works but it is then displayed on every page. How can I get it to show only on the blog pages?

Thanks.

Edit: Here is the entire xml file:

<layout version="0.1.0">
    <default>
        <reference name="footer_links">
            <block type="blog/blog" name="add.blog.footer">
                <block type="blog/tags" name="blog_tags" />
                <action method="addFooterLink" ifconfig="blog/menu/footer"></action>
            </block>
        </reference>
        <reference name="right">
            <block type="blog/blog" name="right.blog.menu" before="-">
                <action method="setTemplate" ifconfig="blog/menu/right" ifvalue="1">
                    <template>aw_blog/menu.phtml</template> 
                </action>
                <block type="blog/tags" name="blog_tags" />
            </block>
        </reference>
        <reference name="left">     
            <block type="blog/blog" name="left.blog.menu"  before="-">          
                <action method="setTemplate" ifconfig="blog/menu/lef开发者_运维技巧t">
                    <template>aw_blog/menu.phtml</template> 
                </action>
                <block type="blog/tags" name="blog_tags" />
            </block>
        </reference>
        <reference name="top.links">
            <block type="blog/blog" name="add.blog.link">
                <action method="addTopLink" ifconfig="blog/menu/top"></action>
                <block type="blog/tags" name="blog_tags" />
            </block>
        </reference>
        <reference name="head">
            <action method="addItem"><type>skin_css</type><name>aw_blog/css/style.css</name></action>
        </reference>
    </default>

    <blog_index_index>
        <reference name="content">
            <block type="blog/blog" name="blog" template="aw_blog/blog.phtml"/>
        </reference>
    </blog_index_index>

    <blog_index_list>
        <reference name="content">
            <block type="blog/blog" name="blog" template="aw_blog/blog.phtml"/>
        </reference>
    </blog_index_list>  
    <blog_post_view>
        <reference name="content">
            <block type="blog/post" name="post" template="aw_blog/post.phtml">
                <block type="socialbookmarking/bookmarks" name="bookmarks" template="bookmarks/bookmarks.phtml"/>
            </block>
        </reference>
    </blog_post_view>
    <blog_cat_view>
        <reference name="content">
            <block type="blog/cat" name="cat" template="aw_blog/cat.phtml" />
        </reference>
    </blog_cat_view>

    <blog_rss_index>
        <block type="blog/rss" output="toHtml" name="rss.blog.new"/>
    </blog_rss_index>
</layout> 


if it's going inside a section then it will be applied to all pages, you want to put the and its contents inside the sections (there'll be the listing page and individual post pages - the sections should already exist in the aw_blog.xml file


It appears on all pages, because you probably put the code in the section of the layout xml. Just put into a section named after the route where it should appear. So try:

<blog>
    <reference name="left">
        <block type="cms/block" name="brand_list">
            <action method="setBlockId"><block_id>brand_list</block_id></action>
        </block>
    </reference>
</blog>


Change XML inside folder theme/layout for example page.xml add something like this to header:

  <block type="page/html_header" name="header" as="header">
        <!-- ... some origin code ... -->
        <block type="page/html" name="custom_block" as="flashHeader" template="customer/custom_header.phtml"/>
  </block>

Create file customer/custom_header.phtml with your custom html code.

Inside template page/html/header.phtml you can add something like this:

$dataCurrentPage = $this->getHelper('cms/page')->getPage()->getData();
$page_id = (isset($dataCurrentPage['identifier'])) ?  $dataCurrentPage['identifier'] : null;
if ($page_id  == 'home' ) { echo this->getChildHtml('flashHeader') }

Flash banner will be show only on homepage.


You can definitely use the custom layout update to place your own static block on left without any coding.

You need to create a static block and then put its reference into custom layout update

<reference name="left">
<block type="cms/block" name="my_left_block" before="-">
    <action method="setBlockId"><block_id>my_left_block</block_id></action>
</block>    

to view an example follow the link below https://lampjs.wordpress.com/2015/07/06/magento-add-static-cms-block-to-category-page-on-left/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜