CakePHP 3.x - 在 head 标签中为特定操作加载 CSS [英] CakePHP 3.x - Load CSS in head tag for a specific action

查看:18
本文介绍了CakePHP 3.x - 在 head 标签中为特定操作加载 CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我只能通过在相应视图文件的 标签中包含该 CSS 文件来为特定操作加载特定 CSS 文件.但是我想在调用特定操作时将该 CSS 文件包含在 标签中?

So far I can only load a specific CSS file for a specific action by include that CSS file within <body> tag from the corresponding view file. But I want to include that CSS file within <head> tag when a specific action is called?

推荐答案

在您的模板中,这可以通过使用 阻止选项:

In your template, this can be achieved by linking to the css file using the block option:

创建指向 CSS 样式表的链接.如果 block 选项设置为 true,则链接标签将添加到 css 块中,您可以将其打印在文档的 head 标签内.

Creates a link(s) to a CSS style-sheet. If the block option is set to true, the link tags are added to the css block which you can print inside the head tag of the document.

即相关模板中的任何位置:

I.e. anywhere in the relevant template:

$this->Html->css('special', ['block' => true]);

这是 fetch 调用的输出布局:

<?= $this->fetch('css') ?>

这篇关于CakePHP 3.x - 在 head 标签中为特定操作加载 CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆