Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Requirements::clear() doesn't work as expected

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

Page: 1
Go to End
Author Topic: 1187 Views
  • justinv
    Avatar
    Community Member
    8 Posts

    Requirements::clear() doesn't work as expected Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Requirements::clear() doesn't work as expected Link to this post

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

  • justinv
    Avatar
    Community Member
    8 Posts

    Re: Requirements::clear() doesn't work as expected Link to this post

    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!

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Requirements::clear() doesn't work as expected Link to this post

    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.

  • justinv
    Avatar
    Community Member
    8 Posts

    Re: Requirements::clear() doesn't work as expected Link to this post

    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.

  • justinv
    Avatar
    Community Member
    8 Posts

    Re: Requirements::clear() doesn't work as expected Link to this post

    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.

    1187 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.