1

I created a static block that I want to add in all of the 1,2,3columns pages from pages. Where should I include this xml code?

   <reference name="content">
                <block type="cms/block" name="home_banner" before="-">
                    <action method="setBlockId"><block_id>top_banner</block_id></action>
                </block> 
   </reference>

This block should be editable from admin panel so I cannot use : getChildHtml function.

UPDATE. If I use this code in the 1,2,3 column phtml files

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('header_robey_banner')->toHtml(); ?>

it works. BUt can it be done by using just xml ?

2 Answers 2

2

As you want to call this static block to all layout then you need to add your code in default handler <default></default>.

This handler is called on all frontend page .It does not matter whatever page layout is

<default><!-- this call default handler -->
<reference name="content">
                <block type="cms/block" name="home_banner" before="-">
                    <action method="setBlockId"><block_id>top_banner</block_id></action>
                </block> 
   </reference>
</default>

You need to call this code at local.xml or any exiting layout files st your Template folder (app/design/frontend/YourPackage/YourTheme/layout)

If you local.xml exit at then it code should be like

(app/design/frontend/YourPackage/YourTheme/layout)

<?xml version="1.0"?>
<layout version="0.1.0">
<default><!-- this call default handler -->
<reference name="content">
                <block type="cms/block" name="home_banner" before="-">
                    <action method="setBlockId"><block_id>top_banner</block_id></action>
                </block> 
   </reference>
</default>
</layout>
1
  • I put it in my local.xml from my theme, and it is not work. Am i missing smth ? Oct 5, 2015 at 12:06
0

if you create the local.xml then add in this inside the <global></global> tag.

app/design/frontend/base/default/layout/local.xml

else add in your page.xml

app/design/frontend/base/default/layout/page.xml
2
  • so <layout><default><global>....</global></default></laypout> in this order ? Oct 5, 2015 at 11:56
  • yes this is the order.. Oct 5, 2015 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.