0

I am using Magento 1.7.

In 1column.phtml under app/design/frontend/default/custom_theme/template/page, which is the page template I'm using, I find the following code:

<?php echo $this->getChildHtml('content') ?>

which is responsible for adding the content to my page.

However, I would like to add some more content to my page, so that it is displayed when this line of code is executed. But I don't know how I should proceed. I read about the layout and blocks system, but still I am not able to add some content to my page.

I know that I can add content to header.phtml or footer.phtml under design/frontend/default/custom_theme/template/page which is then displayed in the frontend. However, in the case of what is inserted by <?php echo $this->getChildHtml('content') ?>, I don't know how to proceed. Could anyone explain me which steps I need to follow in order to add some additional content?

I am pretty new to Magento, so if you think there is some lack of info in my question, please tell me and I will provide it.

2 Answers 2

1

Assuming you just want to add some content via a simple template file you can add the following in your theme app/design/frontend/default/custom_theme/layout/local.xml

<default>
    <reference name="content">
        <block type="core/template" name="custom.content" template="my/custom/template.phtml" />
    </reference>
</default>

Then you just need to create your app/design/frontend/default/custom_theme/template/my/custom/template.phtml file with the content you need inside it

2
  • Perfect, thank you. Now I just added my content, is there any way to control in which position it will appear? Is it just a matter of CSS, or is there another way of arranging blocks using the layout system?
    – LeCodeur
    Commented Apr 10, 2017 at 13:51
  • 1
    @LeCodeur yes you can use before and after attributes in your <block> declaration. The value of those attributes is another block name (defined in the xml layout files). This way you can manage the position Commented Apr 10, 2017 at 13:52
1

Just for your knowledge go to app\design\frontend\base\default\layout\page.xml

<block type="core/text_list" name="content" as="content" translate="label">
                <label>Main Content Area</label>
            </block>

content is a block name defined over there inside

<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml"> </block>

These are structural blocks defined inside page.xml which defines how a page structure should be.

Now if you notice the block type of content block you will see core/text_list. In Magento if a block is core/text_list type then it will call any block inside it automatically.

So as per @Raphael's example

<default>
    <reference name="content">
        <block type="core/template" name="custom.content" template="my/custom/template.phtml" />
    </reference>
</default>

You just need to create the template.phtml file in my/custom/ location. And it will be called automatically.

In other cases(in case of other block types) you need to call that block by using getChildHtml('alias name or name');

2
  • Thank you for the explanation that clarifies it for me. Now I just added my content, is there any way to control in which position it will appear? Is it just a matter of CSS, or is there another way of arranging blocks using the layout system?
    – LeCodeur
    Commented Apr 10, 2017 at 13:50
  • @LeCodeur do as Raphael is saying. Commented Apr 10, 2017 at 13:58

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.