<![CDATA[ Character escaping problems in JavaScript code in TemplateVariable value - My Forums]]> https://forums.modx.com/thread/?thread=89665 <![CDATA[Character escaping problems in JavaScript code in TemplateVariable value]]> https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492977
I have tried using "@CHUNK chunkname" as the value, and also pasting the full code into the Template Variable creation form, but neither seems to work.

Both the data-in-field and @CHUNK method seem to end up with the TV data being embedded in the page editor form (view source) when I edit a page which uses this TV.

I suspect that the problem is caused by the JavaScript code containing the MODx TV value separator ("||"), as follows:

var _paq = _paq || [];


as when I look in the page editor form source it closes the 'value' string after the _paq text and then proceeds with

id="tv_0" name="tv15[]"  onchange="documentDirty=true;" /><label for="tv_0">


at which point my text gets inserted (starting from the beginning again) with the label above closing after _paq (again, getting caught by the TV value separator) and then the rest of my text getting mashed into a checkbox input value with the HTML special characters escaped.

This then gets tangled up with the "Settings" tab in the MODx editor and it all goes wrong from there..

Is there any way that I can safely insert this code into a TV?

I have attached the intended code and the faulty page source as it is probably a bit hard to explain otherwise!

]]>
david55 Mar 18, 2014, 01:21 PM https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492977
<![CDATA[Re: Character escaping problems in JavaScript code in TemplateVariable value]]> https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-493524
(Sorry, I am afraid we have very limited resources and are unable to upgrade or try a test install of a newer version of Evo at present.)]]>
david55 Mar 25, 2014, 07:49 AM https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-493524
<![CDATA[Re: JavaScript code escaping problems in TemplateVariable]]> https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492980 david55 Mar 18, 2014, 01:28 PM https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492980 <![CDATA[Re: JavaScript code escaping problems in TemplateVariable]]> https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492979
<tr style="height: 24px;"><td align="left" valign="top" width="150"><span class="warning">Enable  webstats</span>
			<br /><span class="comment">Tick box to enable webstats for this page (site_webstats)</span></td>
			<td valign="top" style="position:relative;">
			<input type="checkbox" value="<!-- Piwik -->
<script type="text/javascript">


  var _paq = _paq " id="tv_0" name="tv15[]"  onchange="documentDirty=true;" /><label for="tv_0"><!-- Piwik -->
<script type="text/javascript">


  var _paq = _paq </label><br /><input type="checkbox" value=" document.location.protocol) ? "https" : "http") + "://example.org/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "2"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; 
    g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
  })();


</script>
<!-- End Piwik Code -->

<!-- Piwik Image Tracker -->
<noscript>
<p><img src="https://example.org/piwik.php?idsite=2" style="border:0" alt="" />
</p>
</noscript>
<!-- End Piwik -->
" id="tv_1" name="tv15[]"  onchange="documentDirty=true;" /><label for="tv_1"> [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" </label><br />
		</td></tr>
	</table>
            </div>
            <!-- end .sectionBody .tmplvars -->
        
    </div><!-- end #tabGeneral -->

    <!-- Settings -->
    <div class="tab-page" id="tabSettings">
        <h2 class="tab">Settings</h2>
        <script type="text/javascript">tpSettings.addTabPage( document.getElementById( "tabSettings" ) );</script>

        <table width="99%" border="0" cellspacing="5" cellpadding="0">

]]>
david55 Mar 18, 2014, 01:25 PM https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492979
<![CDATA[Re: JavaScript code escaping problems in TemplateVariable]]> https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492978
Intended chunk:

<!-- Piwik -->
<script type="text/javascript">

  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://example.org/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "2"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; 
    g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
  })();

</script>
<!-- End Piwik Code -->

<!-- Piwik Image Tracker -->
<noscript>
<p><img src="https://example.org/piwik.php?idsite=2" style="border:0" alt="" />
</p>
</noscript>
<!-- End Piwik -->
]]>
david55 Mar 18, 2014, 01:24 PM https://forums.modx.com/thread/89665/javascript-code-escaping-problems-in-templatevariable#dis-post-492978