Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Setting order of Javascript in templates

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

Page: 1
Go to End
Author Topic: 519 Views
  • davepolyester
    Community Member
    47 Posts

    Setting order of Javascript in templates Link to this post

    Hey family,

    I'm having trouble getting some javascript to run in one of my templates. If I add the following to the top of my HomePage.ss template, the associated Javascript is called in the head of the rendered page but the slideshow fails to work:

    <% require javascript(mysite/javascript/fadeslideshow.js) %>

    However if I add it to the head section of the Page.ss template, it works fine.

    I also have the following in my Page.ss template:

    On checking the source code of the rendered pages, I see that the slideshow works when fadeslideshow.js is positioned after the jquery.min.js, but fails when it is positioned before it.

    So, how can I force Silverstripe to position the script in HomePage.ss before the script in Page.ss?

  • gaethofs
    Community Member
    9 Posts

    Re: Setting order of Javascript in templates Link to this post

    Hi there!

    Except when you're using the Layout folder, I don't think .ss-files are inheriting when they are on the same level.
    Same for modules, the'll just be overwriting (I think).

    I think it might also be a better approach to load your javascript at the bottom of your site instead of in the header.
    Then I don't really get your question. So you want to put the script of HomePage.ss before the one of Page.ss,
    although they don't inherit anything, at least not implicit? So unless you're using the Layout folder, I don't think this really matters.
    You should just look at one .ss at a time and make sure the jquery is before the other scripts that are using it.

    Did this help you in any possible way? Otherwise you should describe the problem with some more details cause I don't really get it .


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.