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!
So I enter “zend css style sheet” into google and guess what I find…
Cheers mate, still bailing me out on code!
There’s so many cocking functions, it’s easy to get lost in ZF.
BTW, happy bday!
Tim
Hehe, sweet nice one! Does the job, eh?
Thanks very much! Haven’t heard from ya in a while, hope things are all well buddy!
Daze.
[...] David Cooper posted a quick howto on adding CSS to a Zend Framework page, which works and is all well and good, but there was a problem. The code that Zend Framework spits [...]
Do you know a why to set the media attribute via the zend API? I need to be able to define a print.css and ensure the media=”print” attribute is set. So that the final html looks like :