I would like to write an internal style sheet to a view in Zend Framework as such
<head>
<style type="text/css" media="all">
body{ background: #FFFFFF; }
</style>
</head>
I understand that I can write an external style sheet using $this->view->headLink()->appendStylesheet('style.css');
However I cannot find a way to write an internal style sheet. Any ideas?
What you are looking for is called the HeadStyle
view helper. Its manual documentation can be found here.
The HeadStyle
helper's API is consistent will all the Head*
view helpers, and works as such (the following assumes you are in a viewscript):
// Putting styles in order:
// These methods assume the a string argument containing the style rules.
// place at a particular offset:
$this->headStyle()->offsetSetStyle(100, $customStyles);
// place at end:
$this->headStyle()->appendStyle($finalStyles);
// place at beginning
$this->headStyle()->prependStyle($firstStyles);
// Or capturing a block of styles
<?php $this->headStyle()->captureStart() ?>
body {
background-color: <?php echo $this->bgColor ?>;
}
<?php $this->headStyle()->captureEnd() ?>
Note that you do not include the <style>
tags in any of this input. That is generated by the helper itself.
Then, in your layout, simply echo
the helper where you'd like its output:
<head>
<?php echo $this->headLink() ?>
<?php echo $this->headStyle() ?>
</head>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With