Magento 1.9 – How to Insert Block Before Breadcrumbs or After Menu

custom blocklayoutmagento-1.9

I would like to add block to the website (in general on every page) just below menu but not into header, "root" eventually "content".

I managed to add it into content but it's not what I wanted.

=> My layout :

    <reference name="content">
        <block type="core/template" name="banman" before="-" template="banman/block.phtml"/>
    </reference>

This is what I needed to put it there.

Because I'm using Ultimo(latest version), there is a slider before everything else.

Slider is in "root" so I was thinking if I change "content" into "root" then I'll be able to position it before or after slider but it does not work.

I can add it into top.container and it works pretty. But, I can't move it before breadcrumbs.

Doesn't like how it look like if I place it inside menu.Menu bar is far too high.

Best Answer

If you want to add your new block in all pages after the breadcrumbs:

1) app/design/frontend/{package}/{theme}/layout/local.xml

<default>
    <reference name="root">
        <block type="core/template" name="banman" template="banman/block.phtml"/>
    </reference>
</default>

2) app/design/frontend/{package}/{theme}/template/page/1column.phtml

add this:

<?php echo $this->getBlockHtml('banman') ?>

after this:

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

NB: If you want that your block will be just displayed in some page, the same thing but the xml will be changed like this:

<your_layout_handle>
    <reference name="root">
        <block type="core/template" name="banman" template="banman/block.phtml"/>
    </reference>
</your_layout_handle>

EDIT

To display your block with a condition configuration, you have to add your config field in system.xml a multiselect choice to tel to Magento in wich page you want to display your block something like this:

<fields>
    <displayblock translate="label">
        <label>Where you want to display the banman block</label>
        <frontend_type>multiselect</frontend_type>
        <source_model>yourmodule/system_config_source_view</source_model>
        <sort_order>40</sort_order>
        <show_in_default>1</show_in_default>
    </displayblock>
</fields>

You have an exemple here

NB: Dont forget to add this in app/design/frontend/{package}/{theme}/template/page/1column.phtml

if(Mage::getStoreConfig('section/group/field')){
    <?php echo $this->getBlockHtml('banman') ?>
}

EDIT2:

how to insert my block without changing local.xml

Go to your phtml where you want to display your block and add this, you dont need with this the xml

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('path_to_your_block')->toHtml(); ?>

You can set the createBlock('block/type') with your block type.

Related Topic