On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I am trying to create a Template Variable (of type Checkbox) which, when selected, will insert a chunk of HTML (containing mostly some JavaScript code) into the page where it is called.

    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!

    [ed. note: david55 last edited this post 5 years, 11 months ago.]
      Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.
    • Having problems with attachments..

      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 -->
      
        Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.
      • Copy of broken source from the page editor form:

        <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">
        
        
          Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.
        • I just can't win! The escaped HTML characters (quot, lt, gt, etc) appear to have been converted back to normal in my pasted text above..
            Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.
          • Has anybody else encountered this problem (Template Variable value unable to contain "||" string (eg, in JavaScript code)) in this (or a later) version of Evo?

            (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.)
              Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.