Magento Themes and Magento Extensions


Posted on March 5th, 2013 | Posted by admin

Say you want to load a particular script on the page, but only if a particular block loads on that page. As it stands, Magento’s core/template blocks don’t support this.

To do it, include this function from within your custom module’s Block file inapp/code/local/Namespace/Modulename/Block

public function addItem($type, $path)
    $head = $this->getLayout()->getBlock('head');
    return $type == 'css' ? $head->addCss($path) : $type == 'javascript' ? $head->addJs($path) : $this ;

Then to use it, just include a call to this function from within your block declaration in the layout:

How to customize Magento to use a different page template when the cart is empty

Posted on December 31st, 2012 | Posted by admin

Being between projects at the moment and having a bit of beach time on my hands Magento question asked on twitter. So, here’s how to use a different template file when the cart is empty.

First, you’ll have to create a custom Magento extension (if you don’t know how to do that, now is the time to stop reading further and go through some of the Magento documentation and tutorials available). You will only need the etc, controllers and Model directories for this custom extension. As always there are multiple ways to skin a cat, so I will start with the first method:

1. Override the checkout controller’s index action and update the layout

Add the following code to your custom controller class before the call to the renderLayout method

Add Pinterest “Pin It” Button to Magento Product Page.

Posted on November 16th, 2012 | Posted by admin

Want to add a pinterest pin it button to your magento product page . Well it is quite easy and only takes a few steps. You will have your pinterest button working in no time!
First open up your product view.phtml. This file is located in /app/design/frontend/yourtemplate/default/template/catalog/product/view.phtml. Next find the place you want to place it, I recommend next to or above the Quick Description. Add the following code.

Adding an additional content block to your Magento page

Posted on November 13th, 2012 | Posted by admin

It turns out that once you understand Magento’s complicated template layout structure it becomes pretty easy to add content blocks wherever your website needs them. This is just a quick explanation of how that works.

So first things first, find your page layout file. This will be under the app design folder in your themes layout folder and will be named page.xml. This file contins an element called default that (in magento terms) is called a Hook. A hook represents a page, or page type – in this case the default hook is the layout for any page that hasn’t got it’s own specific hook. Usually everything will be defined in here and then the other hooks will add and remove blocks, rather than starting from scratch each time. Inside the hook element you will then find a number of blocks, the most interesting to us are the header and footer blocks. There are other blocks defined but the header and footer are the bext example as they are built using their own templates and contain both specific blocks and a block that can have other blocks added to it (a text_list). Following the same way those blocks work we want to define a block that in our design will go after our pages main content but before the footer. Lets start with the basics…

1 <block type="core/text_list" name="content.footer" as="content_footer" translate="label">
2 <label>Content Footer</label>
3 </block>