I have a quick question here. Let say I have a view file myView.ctp
in cakePHP and inside my view I have some javascript (which I have there for a reason). I know I can tell cake to put my javascript code into the header section of my page by using the scriptStart() and scriptEnd() blocks like:
<?php $html->scriptStart(array('inline' => false)); ?>
// My script code goes here...
<?php $html->scriptEnd(); ?>
The array('inline' => false)
is what actually tells cake to put my script in the header. Now my question is this: How do I achieve the same thing for css codes (WITHOUT putting my css codes into an external file)? This techniques seem to only work for javascript codes.
Thank you
i think you can use this link api13.cakephp.org/class/html-helper
and view style topic. for view example use this link
http://book.cakephp.org/1.3/view/1440/style
$css = $this->Html->tag('style', '/* my css */');
$view =& ClassRegistry::getObject('view');
$view->addScript($css);
The addScript()
function on the view will append your script to the $scripts_for_layout
var.
Edit: Comment reiterated something important I missed so I revised the answer.
Ran into this article when I was looking to do the same thing. Turns out there is now (as of Cake 2.1) a slightly more modern way of accomplishing this using view blocks. To wit:
$styleTag = $this->Html->tag('style', $yourCSS);
// adds your stuff to the "css" block which is injected via "fetch" in
// the head section from the view's layout
$this->append('css', $styleTag);
P.S. Would be nice if there was a HtmlHelper::tag() equivalent for style blocks instead of merely the content, just for cleanliness. Oh well.