Magento Most Frequently Used Function – Every Magento Beginners Should Know

Every Magento Beginners should know

I’m writing this post for the magento beginners. they should know the most frequently used functions in Magento. It helps to reduce the rework while moving the files from one server to another server.

While adding the URLs in CMS/Static Pages, Category or Products most of the peoples always hot coded the URL. so when we move those pages to another server we need to change the URL again. so unnecessarily it takes time. to overcome these issues we need to follow the below format whenever we add the URLs in Magento Admin.

Get Base URL in CMS/Static Blocks:
Let’s assume you want to add your contact us page link ie, http://yourstoreurl.com/contacts in your CMS Page, you need to follow the below.


<a href="{{store url ="contacts"}}">Contact Us</a>

so it automatically points to http:// yourstoreurl.com/contacts

Get Skin/Media URL in CMS/Static Blocks:
Let’s assume you need to show the images from your skin/media directory, for example http://yourstoreurl/skin/frontend/default/default/images/myimage.png

http://yourstoreurl/media/wysiwyg/myimage.png

then you need to follow the below standard


<img src="{{skin url="images/myimage.png"}}" alt="my image"/>


<img src="{{media url="wysiwyg/myimage.png"}}" alt="my image"/>

Call Static blocks from Template File:
Let’s assume you have created the block name called “header-links” . so below is the function to call the block from template file(phtml file).


<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('header-links')->toHTML();?>

Call Block directly from phtml file without defining in Layout File:
If you want to call any template file directly in to another template. you need to follow the below code.

Let’s assume my module name as banner and my block name as banner.php. The phtml file for the block is assumed to be banner/banner.phtml


<?php echo $this->getLayout()->createBlock('banner/banner')->setTemplate('banner/banner.phtml')->toHtml(); ?>

Add Static Block to CMS Page:
Let’s assume we have created the static block called “header-static”. here is the code to call the static block from CMS Page.


{{block type="cms/block" block_id="header-static"}}

How to Call Template File from CMS Page?


{{block type="core/template" name="alias-name" template="cms/mytemplate.phtml"}}

Leave a Reply

Your email address will not be published. Required fields are marked *


7 + 1 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>