【问题标题】:How to use a script block with HTMLBars如何在 HTMLBars 中使用脚本块
【发布时间】:2016-09-21 02:00:27
【问题描述】:

我想在我正在开发的 Ember 网站上使用 Google Adsense。但是,如果我只是复制从 Google 获得的代码块,则会收到此错误:

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

经过一番搜索,似乎有些人有同样的问题,但我没有找到解决方案。有人有什么想法吗?

【问题讨论】:

    标签: ember.js handlebars.js htmlbars


    【解决方案1】:

    将外部脚本放入您的 app/index.html 文件中。

    <!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>
    

    请注意脚本位于content-for 'body-footer' 下方?请记住在 Google Analytics 的管理部分中使用您自己的 Google Analytics 代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      相关资源
      最近更新 更多