1

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.

1 Answer 1

2

<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.

8
  • I used this code already, but by this code it only showing in the blog page and when i moved to another page the block is gone from the right column.
    – Waseem
    Commented Feb 15, 2014 at 11:31
  • You need to define it on those pages where you want to see it. Commented Feb 15, 2014 at 11:35
  • You want this block to be on every page? Commented Feb 15, 2014 at 11:36
  • yes I want this on every page in the blog module
    – Waseem
    Commented Feb 15, 2014 at 11:37
  • Than you need to define it for every page you want to see it on. Commented Feb 15, 2014 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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