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.

General Questions /

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

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

Requirements::clear() doesn't work as expected


Reply


6 Posts   1322 Views

Avatar
justinv

Community Member, 8 Posts

27 June 2010 at 9:07pm

Edited: 27/06/2010 11:48pm

I'm trying to remove all the js includes from my site that seem only necessary for the cms. Can anyone tell me why they're automatically included in my site? And also, why doesn't Requirements::clear() work to remove them - I've had to go through and Requirements::block() each one.

And finally, my goal, how do I remove the Behaviour.register... etc javascript (which I think is included along with the search form)?

Thanks in advance.

Avatar
Willr

Forum Moderator, 5513 Posts

28 June 2010 at 9:04am

When are you calling Requirements::clear()? if its before the requirements are loaded then it won't have anything to clear.

Avatar
justinv

Community Member, 8 Posts

29 June 2010 at 6:45pm

I'm calling it something like this, in a file called HomePage.php which I have created:

function init() {
parent::init();
Requirements::clear();
}

When are the requirements loaded?

I have noticed a second issue which I haven't followed through to the source but have theorised about... I'm writing html5 and I've used <header> </header> tags. I'm finding that the requirements are included twice - once at the end of the <head> section and once at the end of the <header> section. I suspect there's a regex applied somewhere to put the requirements on the page and it matches on </head rather than </head>, and thus matches both my </head> and </header> tags. Is this likely, and if so where can I fix it - in the requirements class??

Thanks Will, you've answered all three of my questions now. You're a legend!

Avatar
Willr

Forum Moderator, 5513 Posts

29 June 2010 at 6:55pm

Ingo very kindly fixed that bug recently - http://open.silverstripe.org/changeset/105667.

If you checkout a daily build of 2.4 (eg http://dailybuilds.silverstripe.com/core-tarballs/silverstripe.2.0.DailyBuild.2010-06-29.tar.gz) this should include the fixes.

Avatar
justinv

Community Member, 8 Posts

29 June 2010 at 6:57pm

Ahh.. I was close, it matches on </head[^>]*> which includes my </header> tag. I wonder if it should actually match on </head> explicitly since the tag wouldn't be a valid closing tag if it had spaces in it (would it?).

I changed mine anyway and that problem is fixed.. still not sure about the Requirements::clear() prob.

Avatar
justinv

Community Member, 8 Posts

9 July 2010 at 9:21pm

I ended up solving my initial problem of Requirements::clear() not working by editing the Requirements.php file to remove the requirements I didn't want. Probably not the best way to do it but worked.