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.

Template Questions /

Setting order of Javascript in templates


Reply


2 Posts   541 Views

Avatar
davepolyester

Community Member, 47 Posts

11 October 2012 at 9:56am

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:

<% require javascript(http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js) %>

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?

Avatar
gaethofs

Community Member, 9 Posts

4 November 2012 at 3:11am

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 :).

Greetings!