Jump to:

1369 Posts in 487 Topics by 520 members

Themes

SilverStripe Forums » Themes » Setting Order of required themedCSS files

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 1498 Views
  • Silverfish
    Avatar
    Community Member
    59 Posts

    Setting Order of required themedCSS files Link to this post

    Hi everybody,

    I'm loading some CSS files with i.e. <% require themedCSS(layout) %>in my main template (Page.ss). In several included layout templates (i.e. HomePage.ss) I load additional CSS files (i.e. require themedCSS(home)).

    In the generated code css files are loaded in reversal order, i.e.
    <link rel="stylesheet" type="text/css" href="http://localhost:8060/themes/mysite/css/home.css?m=1320227911" />
    <link rel="stylesheet" type="text/css" href="http://localhost:8060/themes/mysite/css/layout.css?m=1320076828" />

    Since i would prefer to overwrite the general css declarations in layout.css with the specific declarations in home.css, i need to change the order in which the CSS files are loaded.

    Anyone any hint if and how this is possible?

    Thanx for any answer!

    regards
    SF

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Setting Order of required themedCSS files Link to this post

    No easy way to control the order for any requirements. You can control order a little easier if you use the Requirements PHP api as thats a bit more predictable.

    class Page_Controller extends ContentController {

    function init() {
    parent::init();

    Requirements::themedCSS('layout');
    }

    ..

    class HomePage_Controller extends Page_Controller {

    function init() {
    parent::init(); // will require page::init

    Requirements::themedCSS('home');
    }

  • Silverfish
    Avatar
    Community Member
    59 Posts

    Re: Setting Order of required themedCSS files Link to this post

    Hi Willr,

    thx for your answer!

    Source Code says:

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS('layout');
          Requirements::themedCSS('typography');
          Requirements::themedCSS('form');
       }

    so I don't know if this is deprecated and will be eliminated in future versions?

    Currently i'm doing a workaround, passing Silverstripe CSS mechanics with i.e.:

       <link rel="stylesheet" type="text/css" href="themes/mysite/css/form.css" media="all" />
       <link rel="stylesheet" type="text/css" href="themes/mysite/css/global.css" media="all" />
       <link rel="stylesheet" type="text/css" href="themes/mysite/css/typography.css" media="all" />
       <% if ClassName == HomePage %>
          <link rel="stylesheet" type="text/css" href="themes/mysite/css/home.css" />
       <% end_if %>

    What exactly are the advanteges by loading CSS files via Requirements:: that i miss by doing this?

    Regards
    SF

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: Setting Order of required themedCSS files Link to this post

    I've always wondered the same about the message about Requirements. Is this outdated guidance in the now rather dated BlackCandy theme?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Setting Order of required themedCSS files Link to this post

    Actually what you should be doing these days is using Requirements::combine_files() so you send as few CSS files as possible.

    It's personal preference as to use either the PHP requirements api or the template one, personally I think that message in Page.php is wrong. Including it in the PHP code is often the best (or only way) to do it.

  • Matty Balaam
    Avatar
    Community Member
    69 Posts

    Re: Setting Order of required themedCSS files Link to this post

    Top advice! I'm already combining my Javascript files, so that makes sense to me.

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