简体   繁体   中英

Add Styles to document head from the view in Cakephp?

I need to add styles to my style tag in my head section. How can i add to that style tag from the view.

You'd be better off from an MVC point of view by putting these style elements in to their own stylesheet, and then inserting the sheet in the way mentioned above.

However if you must use internal CSS, this should work:

$this->addScript('extraCSS','<style type="text/css>".foo{color:red;}</style>');

extraCSS I believe is just an internal name given to the content that gets added to the $scripts_for_layout buffer.

This will appear below any JS inclusions, which can be a problem at times.

See all about adding css files using the HTML Helper here: http://book.cakephp.org/view/1437/css

Make sure you have $scripts_for_layout in the head of your layout to have cake put scripts there automatically (see the third example).

EDIT:

For style tags, see here: http://book.cakephp.org/view/1440/style

Otherwise, CakePHP uses simple PHP as the templating language in the view - so just write it using that.

Some example code and further explanation of what you'd like to do would also be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM