Add Content before footer

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);
}