Magento themes and extensions

Addition of Static Block in Magento Template File

Posted on January 7th, 2013 | Posted by admin

Steps to add the static block in magento template files.

There are various ways to add static block in magento frontend.If you are dealing with .phtml and .xml files then this is described how to add the static block in template file. The following steps are:

Steps 1:
First in magento admin panel, navigate to CMS > Static Blocks. Then select “Add New Block” , fill up all the related information and save it.
Step 2:
Call the static block from .xml file where you want to put. Just paste this code in .xml file
<block type=”cms/block” name=”cms_test_block” before=”-”>
<action method=”setBlockId”><block_id>cms_test_block</block_id></action>
remind that here the “name” attribute will be same as “Identifier”.

Get Static Block in Magento

Posted on December 25th, 2012 | Posted by admin

Magento has made it really easy to get Static Content from within a CMS page with the use of widgets, but say you’re developing a custom theme, you may want to call a static block programmatically in a Magento theme in which case there are a few methods of doing so…

The first is quick and easy to drop into a Magento theme, but only gets the static block content:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('indentifer')->toHtml() ?>

Where, by calling the static block model, you can then get all fields associated with that block such as the static block title

Insert Static Block content in template

Posted on December 8th, 2012 | Posted by admin

As magento describes that when we want to add any static block in our magento template, we must add some lines of codes in the XML file. Then we are able to attach related static block in our template. Sometimes we are in hurry and don’t want to update the XML file to insert code in our template. So we can use the following code to insert any static block directly in our template. We just want to make a call to this function :

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('required_cms_block_identifier')->toHtml() ?>

So, By using this code in the template will automatically fetch the content from the static block and insert into our template

Show a static block in html

Posted on July 29th, 2011 | Posted by admin

In one of my previous posts, I wrote about how to show a block in a .phtml file but some people asked me about the static block. So here is the solution:
Please put this piece of code into a correct place of the .phtml file that you want to show a static block.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('my-new-block')->toHtml()

How to call a block directly from a .phtml file?

Posted on July 28th, 2011 | Posted by admin

Sometimes you want to call a block inside a .phtml file without defining in layout. In this case, we can use a method called toHtml of a block.

Assume that we have a block called Mymodule and a template that is located at: mymodule/myblog.phtml

So to generate that block we use:

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

Page 1 of 212»