Magento url and skin url for templates

When you’re working with CMS templates you don’t want to hardcode any urls because when you move it from the development server to the live one you have to go through and change them all again. And then when they move it from the .co.uk to the .com you go through and do it all again.

In WordPress you can add in the following in-built method to automatically output the base url for the site;

<?php bloginfo('url'); ?>

And for your base url of the active template;

<?php bloginfo('template_url'); ?>

So what are the Magento equivalents? Base url;

<?php echo Mage::getURL('') ?>

So to access the jQuery.1.7.2.min.js file in the JS directory it would be;

<?php echo Mage::getURL('js/jQuery.1.7.2.min.js') ?>

And skin url;

<img src="<?php echo Mage::getDesign()->getSkinUrl('images/logo.png');" alt="FreakDem" />

And just while we are doing a WordPress->Magento code comparison post (actually, this isn’t a bad idea – I might formally put a post together for that purpose….) we should do the_permalink(); too;

// WordPress
<?php the_permalink(); ?>
// Magento
<?php echo $this->helper('core/url')->getCurrentUrl(); ?>

Leave a Comment