Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Question about linking CSS files.

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

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

Page: 1
Go to End
Author Topic: 975 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    Question about linking CSS files. Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Question about linking CSS files. Link to this post

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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Question about linking CSS files. Link to this post

    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.

  • micahsheets
    Avatar
    Community Member
    164 Posts

    Re: Question about linking CSS files. Link to this post

    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.

  • sonicparke
    Avatar
    74 Posts

    Re: Question about linking CSS files. Link to this post

    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.

    975 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.