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

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

问题描述

到目前为止,我只能通过将相应视图文件中的< body> 标记中的CSS文件加载到特定操作的特定CSS文件。但是我想在调用特定操作时在< head> 标记中包含该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.

也就是说

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

这是输出布局中的抓取调用

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

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

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