我尝试为某个页面包含自定义css文件。我在PageController Requirements::css()
中使用init()
方法,但我也尝试了模板标记:<% require css(mytheme/css/aa.css) %>
。结果是,生成的页面中没有指向文件的链接。报告没有错误,只是没有效果。调用init()
方法,我可以从内部触发日志。
class AaPage_Controller extends Page_Controller {
public function init () {
parent::init();
Requirements::css("mytheme/css/aa.css");
}
}
我现在走在圈子里,任何有更多SS经验的人都可以提出调试问题的方法吗?
答案 0 :(得分:4)
令人遗憾的是,新的API文档不再显示方法参数的解释,希望它很快得到解决。
如果你look at the code(使用正确的IDE很容易,因为你可以跳转到你正在调用的方法),你会看到:
/**
* Register the given stylesheet into the list of requirements.
*
* @param string $file The CSS file to load, relative to site root
* @param string $media Comma-separated list of media types to use in the link tag
* (e.g. 'screen,projector')
*/
public static function css($file, $media = null) {
self::backend()->css($file, $media);
}
要加载的CSS文件,相对于网站根目录
由于你的主题不在网站根目录,你需要这样的东西:
Requirements::css("themes/mytheme/css/aa.css");
答案 1 :(得分:1)
我建议你使用Requirements::themedCSS
。所以要包含aa.css
,你可以这样做:
Requirements::themedCSS('aa');
在你的模板中:
<% require themedCSS("aa") %>
这样,它会自动在模板文件夹中搜索所请求的资源。
答案 2 :(得分:0)
您的模板文件中是否有head
区域?在Silverstipe将您的需求css文件添加到其中之前,您需要确保您的.ss
文件具有最小值。需要存在类似下面的基本html骨架。
<html>
<head>
<title>Page title</title>
</head>
<body>
</body>
</html>