Caleb Sayre
Caleb Sayre

Reputation: 401

How to use a script block with HTMLBars

I am wanting to use Google Adsense with an Ember site I'm working on. However, if I just copy the code block I get from Google I get this error:

    Error: `SCRIPT` tags are not allowed in HTMLBars templates (on line 3)

After doing some searching, it seems some people has the same issue, but I have not found a solution for this. Does anybody have any ideas?

Upvotes: 0

Views: 154

Answers (1)

Paul Oliver
Paul Oliver

Reputation: 7681

Put external scripts in your app/index.html file.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>TmpApp</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {{content-for 'head'}}

    <link rel="stylesheet" href="assets/vendor.css">
    <link rel="stylesheet" href="assets/tmpapp.css">

    {{content-for 'head-footer'}}
  </head>
  <body>
    {{content-for 'body'}}

    <script src="assets/vendor.js"></script>
    <script src="assets/tmpapp.js"></script>

    {{content-for 'body-footer'}}

    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-12345678-1', 'auto'); // get the exact number from your Google Analytics admin screen
      ga('send', 'pageview');

    </script>

  </body>
</html>

Notice the script is below the content-for 'body-footer'? Remember to use your own Google Analytics code from your admin section in Google Analytics.

Upvotes: 0

Related Questions