Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write internal style sheets in Zend Framework?

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?

like image 761
Marcel Avatar asked Dec 07 '22 06:12

Marcel


1 Answers

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>
like image 88
jason Avatar answered Dec 29 '22 12:12

jason