solved Syntax Error When Copy/Paste Facebook SDK To Widget Or Template

derrickhand300
@derrickhand300
10 years ago
1,353 posts
Trying to add this script that facebook gave me for an app I have made over there
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '791748874238905',
      xfbml      : true,
      version    : 'v2.2'
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

Each time I add it to a widget or a template I get a syntax error- even a blank widget that I aint screwed up yet :)

Just wondering way it's happening and how to correct
updated by @derrickhand300: 12/22/16 11:55:59AM
michael
@michael
10 years ago
7,806 posts
yeah, you cant have {return;} you need to have spaces in between { and the first letter. so make it { return; } and you'll be good to go.

If you were pasting that into an HTML template, you'd be fine, but its a smarty template and smarty looks for {something but ignores {(space)something
derrickhand300
@derrickhand300
10 years ago
1,353 posts
That fixed it-Thank you again!
updated by @derrickhand300: 03/01/15 08:47:31PM
michael
@michael
10 years ago
7,806 posts
No worries. Its just something new to learn, you'll be right for next time :)

Tags