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

Remove CWP script includes when selecting another theme


Go to End


3 Posts   989 Views

Avatar
chasevida

Community Member, 7 Posts

5 February 2015 at 12:40pm

How do you remove the injected script tags that come as part of the default theme when you switch to another theme that does not require them or worse conflicts with these versions?

Primarily I'd like to remove the framework thirdparty jquery scripts which are out of date. It would also be nice to know if there is a way of including these before the closing body tag as opposed to including them in the head.

I've seen that you can do something like the following, but yeah nah all the variations of these I've tried haven't worked.

Requirements::clear(); // not working correctly
Requirements::clear(THIRDPARTY_DIR.'/jquery/jquery.js');
Requirements::clear(THIRDPARTY_DIR.'/jquery-ui/jquery-ui.js');

Avatar
chasevida

Community Member, 7 Posts

5 February 2015 at 12:54pm

Ok this worked, not sure why clear doesn't though.

Requirements::block(THIRDPARTY_DIR.'/jquery/jquery.js'); 
Requirements::block(THIRDPARTY_DIR.'/jquery-ui/jquery-ui.js');

Avatar
camfindlay

Forum Moderator, 267 Posts

6 February 2015 at 10:39am

Hey Chasevida,

I think the more generic question you're asking here is "How do I change the requirement files that are pre-bundled with the CWP recipe code?"

The answer is, overloading methods on the Page.php which inherits from BasePage.php (the underlying page class which is used in CWP to ensure certain features are available in SilverStripe CMS).

Take a look at https://gitlab.cwp.govt.nz/cwp/cwp/blob/master/code/pagetypes/BasePage.php#L462

This is where the group of files are set, and further down the class in the init() method is where they are required and there is a mechanism that minifies and combines these files to improve performance.

By blocking jquery as you have here, you may impact performance of the site once it gets on to a production server.

The better way to approach this would be in Page.php Page_Controller class, to overload the getBaseScripts() method by adding it in your controller and them modifying what is returned.

Just be aware that removing jquery might have impacts elsewhere if there are other jquery plugins used (however if you are rolling your own entire frontend this is likley less of an issue).

As far as the position of the javascript goes... if you properly overload the Requirements as above, it should automatically place the JS in the end of your markup as you are after.

Docs about requirements in general are at http://docs.silverstripe.org/en/developer_guides/templates/requirements/

Interesting that Requirements::clear() isn't working... where about are you putting this?