Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

including CSS in my module


Reply

3 Posts   507 Views

Avatar
ismooth

22 September 2012 at 1:14am (Last edited: 22 September 2012 1:14am), Community Member, 22 Posts

I've made my own module, and now I want to add some css for better data presentation. I've got following file structure:

- sigurnijiinternet
-- css
--- siginternet.css
-- templates
--- RedButtonPage.ss
-- code
--- RedButtonPage.php

I've tried including

<% require css(sigurnijiinternet/css/siginternet.css) %>

into template file. Also with calling themedCSS(siginternet.css) function. I've tried calling Requirements class' css and themedCSS functions from init function of RedButtonPage_controller within RedButtonPage.php file:

public function init() {
parent::init();
Requirements::themedCSS("siginternet");
// Requirements::css("/www/sigurnijiinternet/css/siginternet.css");
// parent::init();
}

Notice the variation on order of calling these functions. Furthermore, I've also tried changing user permissions on all mentioned files, but I never get any css included into the resulting html.

Any hints?

Avatar
martimiz

22 September 2012 at 4:29am (Last edited: 22 September 2012 4:30am), Forum Moderator, 1091 Posts

You probably already found the following documentation for SS2.4 and SS3:
- http://doc.silverstripe.org/framework/en/2.4/reference/requirements
- http://doc.silverstripe.org/framework/en/reference/requirements

<% require css(sigurnijiinternet/css/siginternet.css) %>

Should work... You probaly also know to ?flush=1 if you change a template...

Requirements::css("sigurnijiinternet/css/siginternet.css");

Should work from your pagecontroller init() like you do (but not with the www though, but up from the root of your website)

ThemedCSS now, that will only work if you place your css file in your theme...

Avatar
ismooth

25 September 2012 at 10:33pm Community Member, 22 Posts

martimiz,

Yes, I've checked the documentation, and also tried flushing. I also tried various paths (absolute, relative...) to the css file. What I noticed is that if I don't Include all html code in template file (html, head, body tag....) then css doesn't get included. When I struct template file good, then it gets included - this is okay.

But, I also noticed that some standard css files get included, like default theme's layout.css, js langugage file and so on. I've removed them with Requirements::clear. I guess that's why it's discouraged to include css, js and other files in controller's::init function.

P.S. Maybe a notice could be added in documentation that full html code must be put in template file for template requirements to work?

Cheers