Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Escaping values in a JavaScript string

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

Page: 1
Go to End
Author Topic: 1965 Views
  • mattupstate
    Avatar
    Community Member
    12 Posts

    Escaping values in a JavaScript string Link to this post

    So I've been using the HTML5 boilerplate project as a foundation for my page templates. At the bottom of the main page template I have the following markup:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
    <script>window.jQuery || document.write('<script src="$ThemeDir/js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>

    The problem I'm experiencing is the value \x3C/script> in the 2nd line is being converted to </script>. I believe this is being done by the SilverStripe template engine.

    Is there a way to prevent this conversion from happening so that it remains as \x3C/script>?

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: Escaping values in a JavaScript string Link to this post

    I hit the very same problem today...have been chasing down a fix. Once I find one I will pass it along...and I'll keep an eye on this thread in case you find one before me.

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: Escaping values in a JavaScript string Link to this post

    I went back to using the original unescaped version: "%3E%3C/script%3E" instead of "\x3C/script>"

    I believe the new way H5BP is being converted to a normal PHP string...so try the old way like I did or try to find a different escaping method.

  • mattupstate
    Avatar
    Community Member
    12 Posts

    Re: Escaping values in a JavaScript string Link to this post

    Just discovered putting an additional slash in did the trick as well

    \\x3C/script>

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: Escaping values in a JavaScript string Link to this post

    yep....

    1965 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.