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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

dynamic javascript snippets


Go to End


1633 Views

Avatar
martimiz

Forum Moderator, 1391 Posts

9 July 2009 at 11:24pm

I have this situation where I want to include some javascript depending on whether a specific template is included. I know I can use <% require javascript(... from within my templates, but there doesn't seem to be an equivalent for inline scripts, like <% require customScript(...

I could enter the inline scripts 'manually' but I must use require for the files or Silverstripe will strip them away. Now SilverStripe seems to wait until the last <% require .. %> is found in the templates, and only then loads all files. This way an inline script added manually will sometimes precede the loading of the file it needs...

So I can either create all my little inline scripts as files or call inline scripts from code. As I don't want to create code for these templates, this is not an option. Does this make sense to anyone? Did I overlook some way to add javascript snippets to a template so that Silverstripe will move them to the correct spot?