Linking CSS stylesheet on Zend Framework specific pages

Every so often, at the beginning of a new project at work, I almost always have to add a page-specific stylesheet to a certain page on the project. And usually (almost always it seems) I forget the exact code to enter at the top of the .phtml page.

And I thought I should blog it, so that at least I remember it for future use…

This is for Zend Framework-built sites only, of course, and so long as this is in your <head> section of your bootstrap Index file…

<?php
echo $this->headTitle();
echo $this->headScript();
echo $this->headStyle();
echo $this->headLink();
?>

…Then, on the page we’re talking about, before output on your .phtml file, add the following code

$this->headLink()->appendStylesheet('/path/to/page-styles.css');

Done! So there you are. Some of you might have already known that, maybe some of you have no idea what I’m talking about – but at least I know where to find this damn code again!

Tagged , , | 4 Comments