Block javascript in template
Everyone knows that Requirements::block('/path/to/javascript.js'); in php blocks this file from being loaded. This is important to e.g. require a newer version of jQuery. But you can easily block javascript in your template.
The template code <% require %> can call any method in Requirements class, so this works fine:
<% require block(framework/thirdparty/jquery/jquery.js)%> <% require javascript(themes/mytheme/javascript/thirdparty/jquery.min.js) %>
With this you won't need an extension for controller any more, that just blocks and requires some javascript.
Post your comment
Comments
Larry Stanfield 25/11/2017 9:14pm (7 years ago)
It's a shame you can't find this simple tip on the official docs for silverstripe. I found this useful for remove outdated jquery from a clients site. I couldn't extend the page controller because it's in a set up where the root is off limits, so I used this tip in the main template renderer. Came in handy.
No one has commented on this page yet.
RSS feed for comments on this page | RSS feed for all comments