Technology Powered Knowledge Base
Click Here To Make FREE Audio & Video Call From Web Browser!

Create New Reference in Magento Application to Show Anything

VN:F [1.9.22_1171]
Rating: +14 (from 14 votes)
VN:F [1.9.22_1171]
Rating: 10.0/10 (14 votes cast)

As we already performed some Magento research, we know that it is built on a fully modular model that gives great scalability and flexibility for the development. While creating a theme, provided with many content blocks that we can place in structural blocks. Magento provides few structural blocks by default and many content blocks. We can also create new block.
 
They are the parent blocks of content blocks and serve to position its content blocks within a store page context. Take a look at the image below. These structural blocks exist in the forms of the header area, left column area, right column etc. which serve to create the visual structure for a store page. Our goal is to create a new structural block called “newreference”.
 
Name the structural block

Open the file layout/page.xml in active theme folder. Inside we can find lines like:


 <block type="core/text_list" name="left" as="left" />
 <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.


<block type="core/text_list" name="newreference" as="newreference" />

Now we told Magento that new structural block exists with the name “newreference”. Magento still doesn’t know what to do with it.
 
Tell Magento where to place it
We now need to point Magento where it should output this new structural block. Let’s go to 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.
Let’s assume we wish the “newreference” block to be placed below 2 columns, but above the footer. In this case, our updated file look like this:


<div>
    <div>
	<?php echo $this->getChildHtml('breadcrumbs'); ?>
        <!-- start center -->
        <div id="main">
		<?php  echo $this->getChildHtml('global_messages'); ?>
		<?php  echo $this->getChildHtml('content'); ?>
        </div>
        <!-- end center -->
        <!-- start right -->
        <div>
		<?php getChildHtml('right'); ?>
        </div>
        <!-- end right -->
    </div>
    <div>
		<?php echo $this->getChildHtml('newreference'); ?>
    </div>
</div>

 
Populating structural block
We have the block properly placed, but unfortunately nothing is new on the frontsite. Let’s populate the new block with something. We will put new products block there as an example. Go to appropriate layout XML file and add this block to appropriate place.


<reference name="newreference">
	<block type="catalog/product_new" name="home.product.new" template="catalog/product/new.phtml" />
</reference>
Create New Reference in Magento Application to Show Anything, 10.0 out of 10 based on 14 ratings



Sign Up     Sign In