Archive for August, 2009

Magento – add custom layout template

Tuesday, August 18th, 2009

Current magento version – 1.3.2.4

This is what you need to do to add a new layout template, eg 4 column page layout.

  1. Copy app/code/core/Mage/Page/etc/config.xml
    to app/code/local/Mage/Page/etc/config.xml.
    Creating this new file will allow magento core updates to occure without over-writing your changes (you’ll probably have to look out for changes to the core config.xml to megre them into your custom file).
  2. Register your custom module by adding a new file to app/etc/modules, called something like Mage_Local.xml
  3. In this file add the following code:
    <?xml version="1.0"?>
    <config>
    <modules>
    <Mage_Page> //relates to file structure
    <active>true</active> //set to active
    <codePool>local</codePool> //tell which folder to look in
    <depends> //requires the mage core
    <Mage_Core/>
    </depends>
    </Mage_Page>
    </modules>
    </config>
  4. Now create your new template file, easy way is to copy an existing one such as 3columns.phtml (in app/design/frontend/your_package/your_theme/template/page), and give it a name, such as 4columns.phtml
  5. Register this new template in the config.xml file your created in step 1 by adding your module to the layouts list. For my 4 column example I have added:
    <four_columns module="page" translate="label">
    <label>4 columns</label>
    <template>page/4columns.phtml</template>
    <layout_handle>page_four_columns</layout_handle>
    </four_columns>

You should now be able to access this new template in the cms->manage pages option in the magento admin backend.

Share

Magento – url functions

Friday, August 14th, 2009

Current magento version – 1.3.2.4

Magento had some very handy functions that easily allow you to find some fundamental urls of your site from your phtml files so you can avoid hardcoding them. These are:

  • $this->getBaseUrl() – returns the base url of your store (funnily enough)
  • $this->getSkinUrl() – returns the url of the folder containing your css, images and local js files (eg skin/frontend/default/your_theme, will vary depending on what package and theme the page is using).
    So to find the image logo.gif in the images folder you would call $this->getSkinUrl('images/logo.gif');. It should be noted that if getSkinUrl does not find the file that you have specified (like images/logo.gif) then it will default to looking in the default theme folders rather than your custom theme folders.
  • $this->getJsUrl() – returns the url of the main js folder. So if you want to include a new js library from a template you can use this.

There are probably a few other functions like this, and some variations including some that use the Mage_Core_Model_Store, but there are the ones that I use most often.

Share

Introduction to Magento

Wednesday, August 12th, 2009

Current magento version – 1.3.2.4

Magento Logo

This is a very brief introduction to Magento, a powerful php based open-source e-commerce platform.

I am currently working on my first ever Magento project, and given the flexibilty and complexity of Magento and it’s code base, it seems a good idea to write a series of Magento hints and tips so that the next time that I come to use it I’ll be able to spend less time searching out the solutions to little niggly problems or requirements.

As an e-commerce solution, Magento is extremely powerful and flexible and may well be the answer for many peoples e-commerce needs. However because of this power and flexibility the code base is extremely large and the processing can be a little on the slow side, so if all your looking for is a really small and basic shop then this might prove to be overkill.

Overall though, now that I’ve almost got my head round the basics, I really like Magento as a tool and it can be fairly straightforward to work with if you know what you’re doing. If you’re not sure what you’re doing or you’re trying something a bit new then it can prove to be very frustrating and mentally draining, as the documentation isn’t always great and the forums can prove frustrating. But if you keep at it and in turn share what you’ve learned yourself then you’ll find yourself with a site that does exactly what you want, while at the same time improving the amount of information out there and possibly giving a lifeline to other magento users. If you learn something, share it! It might help someone who could provide you with invaluable help later on!
(more…)

Share

Creating title images on the fly

Monday, August 10th, 2009

I was recently working on a site where the main page headings where required to display in fluxfont (to match some images / icons, plus it looks prettier too). Now this is not a regular font that everyone has installed on their machines, so I needed to come up with some way to display the text in the right font without requiring anyone to download the font themselves.

There are font replacement options out there, such as sIFR and cufon, but these are not guaranteed 100% browser compatible and there is a bit of a grey area regarding the licensing of these fonts (Jon Tan talks a bit about this in his article about font-face). So rightly or wrongly I decided to stay clear of these methods for now and go for an alternative option.

Creating images on the fly using a text string

This method requires the gd and free type libraries to be installed. You can see whether they are or not by looking at phpinfo(), and if you can’t see them referenced then you’ll need to download and install them.

The idea here is to use a php file to manipulate a text string into an image which will then be output to the page.

So first I need to create the php file that will create my image:
(more…)

Share