简体   繁体   English

从Cakephp中的视图添加样式到文档标题?

[英]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. 从MVC的角度来看,最好将这些样式元素放入其自己的样式表中,然后以上述方式插入该表。

However if you must use internal CSS, this should work: 但是,如果必须使用内部CSS,则应该可以使用:

$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. 我相信extraCSS只是赋予添加到$scripts_for_layout缓冲区的内容的内部名称。

This will appear below any JS inclusions, which can be a problem at times. 这将出现在所有JS包含项的下方,有时可能会出现问题。

See all about adding css files using the HTML Helper here: http://book.cakephp.org/view/1437/css 在此处查看有关使用HTML Helper添加CSS文件的所有信息: 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). 确保布局的开头有$scripts_for_layout ,以使蛋糕自动在其中放置脚本(请参见第三个示例)。

EDIT: 编辑:

For style tags, see here: http://book.cakephp.org/view/1440/style 有关样式标签,请参见此处: 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. 否则,CakePHP使用简单的PHP作为视图中的模板语言-因此只需使用它编写即可。

Some example code and further explanation of what you'd like to do would also be helpful. 一些示例代码以及您想做什么的进一步说明也将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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