The random eclecticisms of loonytoons

Magento – url functions

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

One thought on “Magento – url functions

  1. Alex says:

    Thanks for sharing the post, Magento is a robust ecommerce platform that is just right for projects of all complexities. Perhaps because of the all-inclusive code base, creating and editing Magento based code could become a real challenge. Here i found the cheat sheet for magento functions. https://www.cloudways.com/blog/magento-functions-cheat-sheet/

Leave a Reply

Your email address will not be published. Required fields are marked *