2

I have a scenario where i need to place two blocks one after the other in default handle. One block make use of template file while other use static block. Issue i am facing is ordering of the block. I want block with template file first and then static block.

code for layout file is as below

<layout version="0.1.0">
    <default>
        <reference name="content">
            <block type="core/template" name="practiceblock" after="page_content_heading"
                   template="blockpractice/newblock.phtml"/>
            <block type="cms/block" name="practiceCMSBlock" after="-">
                <action method="setBlockId">
                    <block_id>practiceCMSBlock</block_id>
                </action>
            </block>
        </reference>
    </default>
</layout>

I have used after="-" for static block but is still show as below

enter image description here

Any clue for above?

1

4 Answers 4

1

Below is the code that I have used to show template block and then cms block.

<layout version="0.1.0">
    <default>
        <reference name="content">
            <block type="core/template" name="practiceblock" template="blockpractice/newblock.phtml"/>
            <block type="cms/block" name="practiceCMSBlock" after="practiceblock">
                <action method="setBlockId">
                    <block_id>practiceCMSBlock</block_id>
                </action>
            </block>
        </reference>
    </default>
</layout>

Output is

Template Block
CMS Block
2
  • I tried this too. But not working for me.
    – Rakesh
    Commented Jan 3, 2014 at 9:00
  • 1
    @Rakesh If everyone pretty much is giving the same answer and it's not working for you, consider that it is working for you, but because of JS/CSS in your site it's rendered differently in the browser.
    – user4351
    Commented Aug 3, 2014 at 13:45
0

If you want the static block to be displayed after template file your code should be something like this

<layout version="0.1.0">
    <default>
        <reference name="content">
            <block type="core/template" name="practiceblock" after="page_content_heading"
                   template="blockpractice/newblock.phtml"/>
            <block type="cms/block" name="practiceCMSBlock" after="practiceblock">
                <action method="setBlockId">
                    <block_id>practiceCMSBlock</block_id>
                </action>
            </block>
        </reference>
    </default>
</layout>

Hope this will help

6
  • I have already tried this solution, but no luck. Out remains the same . I have my cache disabled.
    – Rakesh
    Commented Jan 1, 2014 at 12:05
  • this should work. I don't see any error in there. Can you please tell me where are you placing this code ?? Also instead of self closing block try using </block>
    – Dexter
    Commented Jan 1, 2014 at 12:29
  • I am placing this code in layout file.
    – Rakesh
    Commented Jan 1, 2014 at 13:09
  • try this thing block type="core/template" name="practiceblock" as="testblock" after="page_content_heading" template="blockpractice/newblock.phtml"/> and add testblock in after instead of practiceblock
    – Dexter
    Commented Jan 1, 2014 at 13:18
  • Can you please try it your self Once .. I have tried all the solution listed so far,But still order is incorrect. I am using a fresh copy of Magento 1.8.
    – Rakesh
    Commented Jan 3, 2014 at 9:00
0

Instead of using layout it is also possible to just echo the CMS block content at the end of template file blockpractice/newblock.phtml just add the following lines, to keep everything simple and in order.

echo $this->getLayout()->createBlock('cms/block')->setBlockId('practiceCMSBlock')->toHtml();
2
  • For this code to work i need to define new Block/Controller Class. which i don't want to. Thanks for your suggestion.
    – Rakesh
    Commented Jan 3, 2014 at 8:20
  • No, just add the above line in template file it should be working. There is no need to define Block/Controller! @Rakesh Commented Jan 6, 2014 at 6:35
0

Following code will work to order block with template file first and then static block:

<layout version="0.1.0">
<default>
    <reference name="content">
        <block type="core/template" name="practiceblock" before="practiceCMSBlock" template="blockpractice/newblock.phtml"/>
        <block type="cms/block" name="practiceCMSBlock" after="practiceblock">
            <action method="setBlockId">
                <block_id>practiceCMSBlock</block_id>
            </action>
        </block>
    </reference>
</default>

Hope this will work for you. :)

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.