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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Question about linking CSS files.

Go to End

5 Posts   1411 Views


Community Member, 165 Posts

18 April 2009 at 5:03am

I see in the BlackCandy Page.php file we have a line:

// Note: you should use <% require %> tags inside your templates instead of putting Requirements calls here. However
// these are included so that our older themes still work

I am wondering why it is better to require the files inside the templates rather than the code file. By my logic I would rather keep that sort of thing out of the template file to simplify things for the person who works on the styling and layout since I pretty much program the site and another person styles it.

I also set things up so that things are very easy for the end user of the CMS interface. I usually make the smallest amount of page types that I can so that the end user isn't confused by a huge list of page types. I make a lot of decisions based on what the parent type of a page is rather than making holders and such. If I want all the child pages of a landing page to inherit the parents Header Image for example I don't make a special page type for the holder and child pages I just set the header style as a parameter in the landing page and all the normal page types that happen to be a child of that one automatically take the header style from the parent. That way all the end user has to do is create a new page and depending on variables that the landing page has they will be conformed to what I want them to be. This way a user can just create new "Page" and never have to worry about new "NewsHolder" or "NewsPage" and such. There are of course times when the page type is too complex for this as is the case for example, a "Blog" page.


Forum Moderator, 5523 Posts

18 April 2009 at 6:18pm

Well SilverStripe supports both as there are times where you want to include CSS and you don't want a custom template so doing it via the PHP is a very good idea, other times if you have a custom template and no blah method you would have to write a function blah() just to include a stylesheet where as you can just have 1 line in the template. A template option gives extra flexibility to the developer without reverting to <link> tages

I personally stick to the PHP option but each to their own.


Community Member, 904 Posts

21 April 2009 at 5:18am

In my opinion, stylesheets are part of the "view" and therefore belong to the templates, not the controller or model. This is especially true for modules, since I often want to customize the look and feel of a module. Now if the module uses the <% require %> control, I can simply create my own JavaScript and CSS, then "require" it from my template files to completely change the look of the module, without changing any of the module files.
If the module writer chose to use Requirements calls, I'm forced to change the module php files in order to change my "view". It also makes module updates quite cumbersome.

Just my 2 cents on this.


Community Member, 165 Posts

21 April 2009 at 8:57am

Thanks for sharing your perspectives on this. I will now have to mull it over and decide what I want to do. I like the control I have in php and how it puts things in an expected order. If I mix the php with the template sometimes things don't load in the order I want them. So I also think that seeing CSS as part of the view and putting them all in the template is a good idea as far as controlling the order goes as well.

Hmmmm. Gonna have to think on it some more.


74 Posts

13 July 2009 at 5:38am

This is quite confusing really. There's got to be a way to put them in the templates & still retain the order that you want. If you do it the suggested way & keep the view in the templates only then the conditional comments are out of order & that seems to defeat the point of using them at all. But I do agree that the view should be in the templates. However, it's got to work & that takes priority over code best practices in my opinion.