Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » require plain CDATA js-code trough function init()

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

Page: 1
Go to End
Author Topic: 1351 Views
  • theAlien
    Community Member
    131 Posts

    require plain CDATA js-code trough function init() Link to this post


    I would like to incorporate some plain CDATA js-code (code that's not in a .js-file) through the function init().
    My js-code uses some data from a database-field, and if I put this variable in a .js-file it breaks.

    So I ended up stuffing the plain js-code in an include-template, but that of course is a bad hack.

    After a while I found out that the plain CDATA js in the default-template is inserted by the validator.php file on line 161:

    function includeJavascriptValidation() {
    $js = <<<JS
    /* javascript here */

    But inserting just a $js = <<<JS ... JS; in the init-method is too easy to be true

    Does someone know how I could require some plain CDATA js-code?
    Or maybe someone knows how to get the data in a databasefield into a required js-file?

    Both ways would be fine.
    NOTE: I'm quite a js-noob

  • Willr
    Forum Moderator
    5511 Posts

    Re: require plain CDATA js-code trough function init() Link to this post

    You have to use Requirements::customScript()


    // your JS here


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.