variables not or not all replaced

linux replace environment variables in file
yaml replace environment variables
sed replace variable in file
bash script replace variable in file
sed replace placeholders
envsubst vs cat
environment variable substitution
docker replace environment variables in file

In the following template I'm using three variables: GA_TRACKING_ID, CC_POPUP_BGCOL and 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>

Fluid can't know if your curly brackets belong to fluid or JavaScript. So it stops if it can't resolve one.

Try to add {whatEver->f:format.raw()}, in your case '{CC_POPUP_BGCOL->f:format.raw()}' and so on.

Replacing only specific variables with envsubst, If a SHELL-FORMAT is given, only those environment variables that are otherwise all environment variables references occurring in standard input are not start with a digit and be nonempty; otherwise such a variable reference is ignored. I replaced all ID's names and texts with random ones. This JSON is written in a file. WinAutomation reads this file and stores it in a variable, which is used in the invoke. The first issues, where the id's aren't variables works fine. The second one with the variables throws errors due to the '%'

If that is a Fluid template, I strongly recommend you should not count on Fluid replacing your variables. In a template that includes JavaScript (especially with {) the Fluid parser is very(!!!) unreliable. Even if you have it working, that does not mean it will work after a Fluid/TYPO3 update or even on a different server.

Avoid it where possible.

I suggest to remove any variable markers from your JavaScript and instead put them into HTML and load them via JavaScript from there.

As an example:

<script id="cookieconsent-script" 
        src="fileadmin/templates/js/cookieconsent.min.js" 
        data-ga-tracking-id="12345ABC"` />

<script>
  var cookieconsentScriptEl = document.getElementById('cookieconsent-script')
  var gaTrackingId = cookieconsentScriptEl.dataset.gaTrackingId
</script>

See https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

Looping variables not replaced by their values, Table[With[{v = v}, {v, #[v] &, # /. x -> v &}], {v, {0, 1}}]. {{0, #1[0] &, #1 /. x -> 0 &}, {1, #1[1] &, #1 /. x -> 1 &}}. getVariablesForChange() is a Map has contains the variables and values. When I running the unit test the replace is corectly fine but I use this in my web application on Tomee Plume the variables does not replaced. For example the variable is: ${TOCHANGE} it looks like this after change TOCHANGE. Docx4j version is: 3.3.6

You can trick Fluid into parsing mode by placing a Fluid tag inside the script tag. When doing so, I always try to separate variable definitions from actual Javascript code as much as possible.

Try something link this.

<script>
      <f:comment>Wake up, fluid!</f:comment>
      var ccbackground= "{CC_POPUP_BGCOL}";
      var cctext = "{CC_POPUP_TXTCOL}";
      var cctrackingId = "{GA_TRACKING_ID}";
</script>

<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=cctrackingId";
    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', 'cctrackingId', { 'anonymize_ip': true });
      testfunc('ccbackground', 'cctext');
    }
  }

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

  window.cookieconsent.initialise({
    "palette": {
      "popup": {
      "background": ccbackground,
      "text": cctext
      },
      "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>

Replacement from Variable, The variable is replaced in the Variables screen with each data release. Not a hierarchy node variable; Input ready; Must exist in the query; Screen area In all other cases (if the basic characteristics are not the same, or replacement is to be � Template variables are not replaced #223. Closed jpetitcolas opened this issue Feb 15, 2016 · 8 comments Closed Template variables are not replaced #223.

Replacement Path: Replacement from Variable, (The source variable is not allowed to be a hierarchy node variable.) In all other cases (if the basic characteristics are not the same, or replacement is to be � You want to do this with several variables: use foreach. sort or gsort once, replace all variables using foreach, and, if necessary, sort back again. You have panel data, so the appropriate replacement is a neighboring nonmissing value for each individual in the panel. Suppose that individuals are identified by id.

Not all variables in the JSON body get replaced � Issue #5682 , Dear Postman Team, I noticed that a certain POST request is failing as some of the variables don't get replaced: For example I'm using nested� Hello, I've updated cacti from 1.1.6 to 1.1.38. After the update, the graph names for new created graphs are not replaced with variables. Instead all are called: "|host_description| - Traffic - |query_ifAlias|".

Variables not being replaced in media queries declaration � Issue , Both variables and @import rules within @media queries are not converted and are just output as they are not converted at all. Let's asume I have core.less file� expr /. rules applies a rule or list of rules in an attempt to transform each subpart of an expression expr. ReplaceAll[rules] represents an operator form of ReplaceAll that can be applied to an expression.

Comments
  • It's not working: codebackground": "{CC_POPUP_BGCOL->f:format.raw()}",/code
  • Did you use it on all variables?
  • Yes but now it's working with <f:format.raw>{CC_POPUP_BGCOL}</f:format.raw>
  • Hmm, not so nice to read in the code but good to know. Anyway @jonas is right, none-fluid curly brackets are terrible and should be avoided. I made me a custom viewHelper to render fluid variables to an js object.
  • I agree with Jonas Eberle that most of the JS should be on a .js file and included in the template (either with typoscript or with a script tag in the fluid template). JS variables should also be defined in the typoscript template (using dedicated properties of PAGE). You can also read this part of the documentation: docs.typo3.org/m/typo3/guide-extbasefluid/master/en-us/Fluid/… where the specific issue of JS in fluid is addressed, with all the possibles workarounds.