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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

including CSS in my module

Go to End

3 Posts   1147 Views


Community Member, 25 Posts

22 September 2012 at 1:14am

Edited: 22/09/2012 1:14am

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
-- 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() {
            // 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?


Forum Moderator, 1391 Posts

22 September 2012 at 4:29am

Edited: 22/09/2012 4:30am

You probably already found the following documentation for SS2.4 and SS3:

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

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


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...


Community Member, 25 Posts

25 September 2012 at 10:33pm


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?