There is often a need to create a new position in Magento apart from the default one. In Magento we call it References. Now the question is How To Create One ?.
It’s pretty simple to add new Reference in Magento. Below are the steps on how to do it.
First thing we need to do is Create a New Structural Block.
Step 1 : Name the Structural Block
Open the file layout/page.xml in your active theme folder. Inside you will find lines like:
<block type=”core/text_list” name=”content” as=”content”/>
<block type=”core/text_list” name=”right” as=”right”/>
Let’s mimic this and add a new line somewhere inside the same block tag.
Now we told Magento that new structural block exists with the name “newreference”. Magento still doesn’t know what to do with it.
Step 2: Tell Magento where to place it
We now need to point Magento where it should output this new structural block. Goto template/page folder in our active theme folder. You will notice different layouts there. Let’s assume we want the new structural block to appear only on pages that use 2-column layout with right sidebar. In that case we should open 2columns-right.phtml file.
Now, we wish to show the newreference above the footer as shown in the figure. To do so we will need to open the file 2columns-right.phtml and insert the code
into the file. The code will look something like this.
<?php echo $this->getChildHtml(‘breadcrumbs’) ?>
<?php echo $this->getChildHtml(‘global_messages’) ?>
<?php echo $this->getChildHtml(‘content’) ?>
<div class=”col-right sidebar”><?php echo $this->getChildHtml(‘right’) ?></div>
<div><?php echo $this->getChildHtml(‘newreference’) ?></div>
Step 3: Entering data for that structural block
We have the block properly placed, but unfortunately nothing is new on the frontsite. Let’s populate the new block with something. So let’s create new file app/design/frontend/[base]/[default]/template/newreference.phtml with the following content:
You can put any content or images in this file apart from text.
Go to appropriate layout XML file (page.xml) and add this block to appropriate place (for testing purpose you could place it under “default” handle).
<block type=”core/template” name=”newReferenceBlock” template=”newReference.phtml” />
Now if you visit your frontend you will see the new reference text.
PLease leave your comment in case of any doubts. Please provide your feedback on it.