Reputation: 1724
I try to include custom css file for a certain page. I use Requirements::css()
method in the PageController init()
, but I also tried the template tag: <% require css(mytheme/css/aa.css) %>
. The result is, there's no link to the file in generated page. There are no errors reported, just no effect. The init()
method gets called, I can fire log from inside of it.
class AaPage_Controller extends Page_Controller {
public function init () {
parent::init();
Requirements::css("mytheme/css/aa.css");
}
}
I'm walking in circles now, could anyone with more SS experience suggest a way to debug the problem?
Upvotes: 0
Views: 844
Reputation: 5875
I suggest you use Requirements::themedCSS
. So to include aa.css
, you could do:
Requirements::themedCSS('aa');
And in your template:
<% require themedCSS("aa") %>
This way it'll automatically search the template folder(s) for the requested resource.
Upvotes: 1
Reputation: 4626
It's a shame that the new API docs don't show the explanation of the method parameters any more, hopefully it's fixed soon.
If you look at the code (which is easy with a proper IDE, cause you can jump to the method your're calling) you'll see :
/**
* 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);
}
The CSS file to load, relative to site root
As your theme is not at the site root, you need something like this:
Requirements::css("themes/mytheme/css/aa.css");
Upvotes: 4
Reputation: 879
Do you have a head
area in your template file? You'll need to make sure that your .ss
file has the bear minimum before Silverstipe will add your requirements css file to it. A basic html skeleton like the one below needs to be present.
<html>
<head>
<title>Page title</title>
</head>
<body>
</body>
</html>
Upvotes: 0