Question

I am using magento 1.9.2.2 version. I want to add content from custom module before footer (after all page content) without change any core file and theme files ( .phtml ) .

Was it helpful?

Solution

This is possible with CMS configuration only and no code:

  1. create a static block (CMS > Static Blocks) that contains your content

  2. Create a new widget instance (CMS > Widgets) and select your theme screenshot (2)

  3. Add Layout Update for page "All Pages" and reference "Page Footer" (this is a container within the page footer) - or "Content" if you want it to be part of the content (i.e. not span over all columns)

screenshot (3)4. Select static block from (1) in "Widget Options": screenshot (4)

  1. Save.

  2. Clean cache.


Without manual configuration

If this is for an extension, you can use a custom template and the following layout XML instead:

<default>
    <reference name="bottom.container">
        <block type="core/template" before="-" name="example" template="your_module/your_template.phtml" />
    </reference>
</default>

The template will be part of the footer, if you want it to be part of the content, see below:

Add a block programmatically to all pages at the end of the content

Unfortunately, this does not work as desired:

<default>
    <reference name="content">
        <block type="core/template" after="-" name="example" template="your_module/your_template.phtml" />
    </reference>
</default>

This is because the default layout handle is applied before any page specific layout handles, so although we add the custom block "after all blocks that are already added", the actual content will be added later, after our custom block.

So you have to add your block after all layout XML updates are processed and this is possible with an observer for the controller_action_layout_load_before event. The observer will look like this:

public function addBlockAfterContent(Varien_Event_Observer $observer)
{  
    $layout = Mage::getSingleton('core/layout');
    $content = $layout->getBlock('content');
    $newBlock = $layout->createBlock('core/template', 'example_block_name');
    $newBlock->setTemplate('your_module/your_template.phtml');
    $content->append($newBlock);
}

OTHER TIPS

It is only possible with this type of core/text_list block.

core/text_list: Some blocks like content, left, right etc. are of type core/text_list. When these blocks are rendered, all their child blocks are rendered automatically without the need to call the getChildHtml() method.

Otherwise you have to use getChildHtml() in your theme file.

You can use like:

<reference name="content">
        <block type="core/template" after="-" name="test2" template="test.phtml" />
    </reference>

Please follow below code:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="root">
            <block type="core/text_list" name="newreference" as="newreference" translate="label">
                <label>New Reference</label>
            </block>
        </reference>
        <reference name="newreference">
            <block type="core/template" name="newreferenceblock" template="newreference.phtml" />
        </reference>
    </default>
</layout>

Reference: Add a New Reference in Magento

In latest versions you could use the footer_before position for this.

<default>
  <reference name="footer_before">
      <block type="core/template" name="customblock" template="customblock.phtml" />
    </reference>
</default>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top