Posted by: james | October 3, 2009

How to Create Static Block in magento

<li><a href=”<?php echo $this->getUrl(”)?>”><?php echo $this->__(‘Home1’) ?></a></li>
<li><a href=”<?php echo $this->getUrl(‘warranty/form’)?>”><?php echo $this->__(‘Warranty’) ?></a></li>

Steps to create static block in magento..

first of all go to app/design/frontend/default/default/template/form/data.phmtl

//now here create your own template i have just write code to dispaly hi.

so in data.phtml

<?php
echo “hi”; exit;

?>

now go to app/code/local/Display/Form/Block/Data.php

<?php
class Display_Form_Block_Data extends Mage_Core_Block_Template
{
public function doSomeAction()
{

}
}

now go to app/code/local/Display/Form/etc/config.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<Display_Form>
<version> 0.1.0 </version>
</Display_Form>
</modules>
<global>
<blocks>
<Display_Form>
<class> Display_Form_Block </class>
</Display_Form>
</blocks>
</global>
</config>

dont’ forget to add xml file in etc.so now go to app/etc/Display_Form.xml
<?xml version=”1.0″ encoding=”UTF-8″?>

<config>
<modules>
<Display_Form>
<active>true</active>
<codePool>local</codePool>
<version> 0.1.0 </version>
</Display_Form>
</modules>
</config>

// here your template and view block part has completed. Now its time to display that block on particular page, let’s say you want to display that block on home page, then go to admin panel.

in admin panel click on CMS–>Mange Pages, now you will get list of whole pages, in that click on home page. and in that at the last you will get content. in that at last put this code.

<div>
Example’s Output:
{{block type=”Display_Form/data” template=”form/data.phtml”}}
</div>

and now save this page and check it on home page so at last you will get output of your code..
its an easy because its a static page but if you want to add it at any other page which is coming from any xml file like checkout page or catalog page or product page or customer account page, then you have to specify this block to that particular xml. and also you can give position for that block in that xml file.

for ex.you want to display that block at product view page..

remaining– how to put that block in different pages. please check it..

while defining block in that block type means like getBlock class call. means in type before ‘/’ its a module name and after ‘/’ it will file name and if it is with under score then there will one folder and in that file will there.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: