How to Set Default Layout for Custom Module – Magento 1.8

layoutmagento-1.8

I am working on my first module and I stuck with frontend layout.

I created a block which I want to display in the right column.

In my layout.xml when I put my code in the default tag it is showing in my whole website, so i tried using this code blog_default tag but it is not showing anything.
How can I display my block in the right column.

Here is my layout.xml file

<?xml version="1.0"?>   
<layout version="0.1.0">
<default>
 <reference name="root">   
  <action method="setTemplate"><template>page/3columns.phtml</template></action>   
</reference>
</default>
<blog_default>
  <reference name="right">
   <block type="blog/category_list" before="-" name="blog.category.list">
    <action method="setShowPopulatedOnly" ><show>1</show></action>
   </block>
   <block type="blog/widget_post_list" after="blog.category.list" name="blog.latest.posts"/>
 </reference>
</blog_default>
<blog_index_index>   
 <reference name="content">   
  <block type="blog/article_index" name="blog_index" template="blog/article/index.phtml"/>   
</reference>   
</blog_index_index>   
</layout>

by this the right column is not showing my block. How can I display my block.

Best Answer

<default> is used for all pages of the site.

As I understood you want to display your block on every page of your blog controller.

But magento does not support that. You need to place your block definition in every module controller_action_handle.

<?xml version="1.0"?>   
<layout version="0.1.0">
    <default>
        <reference name="root">   
            <action method="setTemplate"><template>page/3columns.phtml</template>     </action>   
        </reference>
    </default>
    <blog_index_index>   
        <reference name="right">
            <block type="blog/category_list" before="-" name="blog.category.list">
                <action method="setShowPopulatedOnly" ><show>1</show></action>
            </block>
            <block type="blog/widget_post_list" after="blog.category.list" name="blog.latest.posts"/>
        </reference>
        <reference name="content">   
            <block type="blog/article_index" name="blog_index" template="blog/article/index.phtml"/>   
        </reference>   
    </blog_index_index>
    <layout_handle>
        <reference name="right">
            <block type="blog/category_list" before="-" name="blog.category.list">
                <action method="setShowPopulatedOnly" ><show>1</show></action>
            </block>
            <block type="blog/widget_post_list" after="blog.category.list" name="blog.latest.posts"/>
        </reference>
    </layout_handle> 
 </layout>

Where layout_handle is layout handle of every page you want to see a block.