Tech-Today
Magento's Block and Template
This blog is not the authors original, instead his notes on the key steps in playing with blocks and templates.
Objective: To create a block that will call a template and will be displayed on the home page.
Steps:
1.) Create a namespace inside the local directory, ex. Kalidad.
2.) Create another folder inside the Kalidad, ex Candles.
*this makes local/Kalidad/Candles.
*Candles is a module
3.) Inside the Candles there are a number of predefined subdirectory that can be created. We will create the minumum for this tutorial.
Let us create:
Kalidad/Candles/Block - module blocks
Kalidad/Candles/etc - where configuration files are stored
4. Then create the configuration file inside etc. Let's name it config.xml.
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Kalidad_Candles>
<version>0.1.0</version>
</Kalidad_Candles>
</modules>
<global>
<blocks>
<Kalidad_Candles>
<class>Kalidad_Candles_Block</class>
</Kalidad_Candles>
</blocks>
</global>
</config>
Tags that requires special attention:
a.) blocks should be place inside the global tag, or it will not be read
b.) specify the class, take note: Kalidad_Candles_Block - _ is replaced by / which correspond to its directory
5.) Create a file named Price.php inside Block, insert the below codes:
<?php
class Kalidad_Candles_Block_Price extends Mage_Core_Block_Template {
public function getPrice() {
$msg = "showPrice";
return $msg;
}
}
?>
*This is our block, which we will call in our template to display a text.
6.) Define a template inside the selected theme: app/design/frontend/default/default/template/ (assuming we used the default template).
The folder will be name kalidad: app/design/frontend/default/default/template/kalidad
7.) Inside the kalidad template, create a file named price.phtml and insert the following code:
<h1>Kalidad Price</h1>
<?php echo $this->getPrice(); ?>
8.) Now, we need to create a configuration that will notify the magento of our newly created module.
Inside app/etc/modules, create Kalidad_Candles.xml <- code="" codes:="" ff="" insert="" is="" module.="" our="" the="" this="">
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Kalidad_Candles>
<version>0.1.0$lt;/version>
<active>true$lt;/active>
<depends>$lt;/depends>
<codePool>local$lt;/codePool>
</Kalidad_Candles>
</modules>
</config>
->
9.) For the changes to take effect clear the var/cache directory (delete everything - crucial), or inside magento;s admin System->Cache Management, disable all the items.
10.) If everything goes well, we should see our newly created module inside magento's System->Configuration->System.
11.) Change the home page. Goto magento's CMS->Manage Pages. Select Home Page and insert the following codes:
{{block type="Kalidad_Candles/price" template="kalidad/price.phtml"}}
That's it.
-
How To Create A Modularized Ear Project In Maven
This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api). How it looks like (assuming our top project is named ipiel): +ipiel +ipiel-ear...
-
Web Development
WordpressConfigure Custom Wordpress PermalinkZencartHow to add a customize product admin fields in zencart by editing/adding extra codesJoomlaHow to install/setup/configure joomla to run in a xampp setup. This avoids the technical detail of manually installing...
-
Create A Magento Extension That Will Only Allow A Customer To Login Until A Given Expiry Time
Long time ago I was assigned to modify magento, add an expiry date and check if the costumer is expired during login. Those times resource were scarce and what I did was hacked magento, add custom codes and fields in the database. Which is not a good...
-
Magento Change Label Of My Wishlist, Etc:
Magento change label of My Wishlist, etc: This works for me: I've change all the wishlist instances in these csv files: app/locale/en_US/ Mage_Adminhtml Mage_catalog Mage_Checkout Mage_Customer Mage_Reports Mage_Sales Mage_Tag Mage_Wishlist Make sure...
-
Custom Magento Module Not Showing In System->configuration->advance
Well, after following these tutorials: http://activecodeline.com/writing-a-custom-module-in-magento-detailed-walktrough/ http://www.magentocommerce.com/wiki/how-to/create-payment-method-module I still cannot see my custom module in the system->configuration->advance...
Tech-Today