如何逃脱dwoo中的花括号?

时间:2015-01-03 13:47:51

标签: google-analytics dwoo

当我尝试将Google Analtics跟踪代码插入我的dwoo模板时

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-1', 'auto');
  ga('send', 'pageview');
</script>

我得到了

Fatal error: Uncaught exception 'Dwoo\Exception\CompilationException' with
message 'Compilation error at line 25 in "file:templates/template.html"

位于我的分析代码中(第25行是以(function(...开头的第一行)。我认为这是由于花括号。是否像在Twig中那样{% raw %}

1 个答案:

答案 0 :(得分:1)

我已经发现了,你必须将这样的代码转义为{"..."}

  {"(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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXX-1', 'auto');
  ga('send', 'pageview');"}

See documentation: Dwoo for Designers, HTML Escaping