Search code examples
xmlmagentoblock

Magento Blocks displays in the footer?


This is probably a pretty basic question. I made a custom block in my page.xml and I placed it in the header block. But it shows at the bottom of my page. I searched for tutorials and user guides, but I couldn't find anything.

<block type="page/html_header" name="header" as="header">
    <block type="page/template_links" name="serie.menu" as="serieMenu" output="toHtml" template="page/html/series.phtml" />
</block>

Solution

  • Inspect your HTML, see where the block HTML is being rendered. If it's outputting the HTML in the header, but appearing at the bottom, it's most likely CSS positioning the block where you see it.

    I recommend not modifying page.xml, but creating a local.xml file in your layouts directory and including your block definition there. You can use the <reference> tags to target a specific block, and inject your block inside of it.

    For example, since you want to target the block named header, you can use <reference name="header"> to target that specific block, and define your own block definition.

    To do so, you would create the file /layouts/local.xml file in your theme directory, and include the following in the file:

    <?xml version="1.0"?>
    <layout version="0.1.0">
    
        <!-- Default handle, loaded on most pages -->
        <default>
            <reference name="header">
                <block type="page/template_links" name="serie.menu" as="serieMenu" output="toHtml" template="page/html/series.phtml" />
            </reference>
        </default>
    
    </layout>
    

    Now that your block is defined for the header, you can now call it in your templates/page/header.phtml file. You can output your block like this:

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

    Remember that modifiyng layout files will require you to flush your Magento caches, if you have cache management enabled.