CakePHP 3.x - Load CSS in head tag for a specific action

我与影子孤独终老i 提交于 2019-12-03 18:12:09

问题


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?


回答1:


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

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]);

This is output by the fetch call in the layout:

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


来源:https://stackoverflow.com/questions/37457293/cakephp-3-x-load-css-in-head-tag-for-a-specific-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!