Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » ss fails totally at linking to javascript and 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: 596 Views
  • marcink
    Avatar
    Community Member
    89 Posts

    ss fails totally at linking to javascript and css files Link to this post

    hi,

    as much as i love ss for its immense possibilities, its ease of use (even if i hate php - its such a ugly language...) as much i hate how it handles requirements.

    i was at this point like 2 years ago and since then nothing changed.

    can any on tell me, how and why a linked js file in a include (.ss) can be above requirements that are defined inside the head tag???
    (when i talk about required, i mean: <% required javascript(...) %>)

    that's just plain stupid.
    i understand that there can be no absolute solution to that. but at least respect that js/css files that are defined as required in the head are please, please be included on top of the other files?

    is that really too much asked for??

    so, now that i cooled down, is there now a solution to this? did i miss something?

    any help appreciated...

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: ss fails totally at linking to javascript and css files Link to this post

    That is the expected behaviour, as it's impossible to know if something included using Requirements is needed for something in those hardcoded blocks to work, they're put above it, just in case.

    You can use Requirements::insertHeadTags('<script src="blah.js"></script>'); in the init() method in your Controller subclass to ensure that something goes in the head and doesn't cause other included things to be put before it (it adds right before </head>).

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: ss fails totally at linking to javascript and css files Link to this post

    i was just about to clarify my post, as it is indeed confusing.

    it's ok to add all js to the end of the html document. i agree with that.
    and of course (as i mentioned) ss can not know what order the requirements in some include files should have.

    but:
    it should be quite obvious, that linked files in the Page.ss or Page.php (or the equivalent - the top most page subclassing Page.php or SiteTree.php)
    should be placed on top of others. and all js defined in a include - way down in hirarchy - should be placed belowe.

    am i wrong? i can't see a case where this order wouldn't work.

    pls tell me your thoughts on this.

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