变量未全部或未全部替换

问题描述 投票:0回答:1

在以下模板中,我使用三个变量:GA_TRACKING_ID,CC_POPUP_BGCOL和CC_POPUP_TXTCOL

<script src="fileadmin/templates/js/cookieconsent.min.js" data-cfasync="false"></script>
<script>
  function loadGAonConsent(){
    var gs = document.createElement("script");
    gs.async = true;
    gs.src = "https://www.googletagmanager.com/gtag/js?id={GA_TRACKING_ID}";
    var h = document.getElementsByTagName("head")[0];
    h.appendChild(gs, h);
    gs.onload = function (){
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments)};
      gtag('js', new Date());
      gtag('config', '{GA_TRACKING_ID}', { 'anonymize_ip': true });
      testfunc('{CC_POPUP_BGCOL}', '{CC_POPUP_TXTCOL}');
    }
  }

  if(document.cookie.split(';').filter(function(item){return item.indexOf('cookieconsent_status=allow') >= 0}).length)
    loadGAonConsent();

  window.cookieconsent.initialise({
    "palette": {
      "popup": {
      "background": "{CC_POPUP_BGCOL}",
      "text": "{CC_POPUP_TXTCOL}"
      },
      "button": {
      "background": "#4b81e8"
      }
    },
    "theme": "classic",
    "type": "opt-in",
    "content": {
      "policy": "policy",
      "message": "message",
      "deny": "deny",
      "allow": "allow",
      "link": "link",
      "href": "#"
    },
    onStatusChange:function(status,chosenBefore){
      if(this.hasConsented())
        loadGAonConsent();
    }
  });
</script>

GA_TRACKING_ID的所有外观均按预期设置,但JS-Funktion“ window.cookieconsent.initialise()”中并非全部CC_POPUP_xxx。

所以我在调用“ gtag()”之后添加了对不存在的func“ testfunc('{CC_POPUP_BGCOL}','{CC_POPUP_TXTCOL}')”的调用(以模拟一个简单的函数调用),并且令人惊讶的是这两个外观被替换。有人可以解释吗?

typo3 typoscript substitution
1个回答
0
投票
流体不知道您的大括号是属于流线型还是JavaScript。因此,如果无法解析,它将停止。
© www.soinside.com 2019 - 2024. All rights reserved.