Magento: Get the skin url

When editing Magento tempates or CMS pages you will have a need to access images and other content inside the skin/—/images folder. Instead of making hard coded links in the CMS or templates a better way is to get this from Magento (one of the many reasons for doing this is that it will still work if something in the directory structure is changed – like say you dev server is dev.something/shopverige but the live store is directly on a domain like say http://www.shopsverige.se

Here is how to do it:

<!-- this is inside of .phtml files -->
<img src="<?php echo $this->getSkinUrl('images/coolimage.png'); ?>" alt="arrow"/>
 
<!-- use this is in cms block -->
<img src="{{skin url='images/coolerimage.png'}}" alt="" />

Internet Explorer not rendering empty div correctly

Internet Explorer won’t render empty divs correctly.

I had a div with a height and a background image but no content; It was not rendered with the correct height it was only like one line.

A work around for this is to have some “content” inside the div (like a whitespace, a comment or why not both) then Internet Explorer renders the correct height.

<div class="some-class-with-size-and-background">
&nbsp;<!-- keep to get IE to render this div -->
</div>

PHP5: Quick on calling a parents constructor

Using OOP there comes a need to call the constructor of a parent class, this is not hard to do

class TestParent {
    public function __construct() {
        var_dump('blah');
    }
}
 
class TestChild extends TestParent {
    public function __construct() {
        parent::__construct();
    }
}
 
$a = new TestChild(); //Output will be: string 'blah' (length=4)

In PHP4 this would have looked like (this still works in PHP5)

class TestParent {
    public function TestParent() {
        var_dump('blah');
    }
}
 
class TestChild extends TestParent {
    public function TestChild() {
        parent::TestParent();
    }
}
$a = new TestChild(); //Output will be: string 'blah' (length=4)