We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46039
    • 76 Posts
    Hi all,

    I have a very basic HTML Tag TV that outputs some page JS to a <script> tag, but instances of || double pipes cause the output to be split into a new <script> tag. I know || is used as a delimiter in some TVs in MODX so I'm curious whether this is a feature or a bug in the HTML Tag TV?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Can you be more specific about the exact TV you are using? Input type? I'm not familiar with an "HTML tag" type.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 46039
        • 76 Posts
        Hey, sorry. Output type is 'HTML Tag' and I've used it with 'text', 'textarea' and 'rich text' input types.

        e.g.

        Input set to: 'text' with content

        test || test


        Output set to: 'HTML Tag' with the tag name div

        Will give:

        <body>
        
        <div id="tvtesting0">test </div><div id="tvtesting1"> test</div>
        
        </body>

          • 28042 ☆ A M B ☆
          • 24,524 Posts
          How interesting. It does, indeed, view the double-pipe as a delimiter.

          In modtemplatevar.class.php, the parseInput() function will return the input as a string if it contains ||, then the parseInputOptions() function will automatically explode() any input string on ||, then the code will apply the output modifications to each item in the resulting array.

          I can see how that might be a useful feature in some cases, but it's obviously a problem in other cases.

          My decision on that would have been to presume that, except for a few specific input types, people know what they are entering into the TV field, and that's what they want to get out. Arbitrarily and inflexibly deciding that || is always a separator, in my opinion, is unnecessarily restricting the user's ability to do what he intends to do.

          What's ironic about this is that the modtemplatevar.class.php code itself uses || for "or" 17 times.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 20413
            • 2,877 Posts
            Quote from: sottwell at Jun 12, 2014, 01:24 PM
            ...deciding that || is always a separator, in my opinion, is unnecessarily restricting the user's ability to do what he intends to do.

            What's ironic about this is that the modtemplatevar.class.php code itself uses || for "or" 17 times.

            +1

            Meanwhile try replacing || with:
            &[+removethisPlaceholder+]#124;&[+removethisPlaceholder+]#124;

            or:
            |\| 


            great tool: http://www.the-art-of-web.com/javascript/escape/
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
              • 3749
              • 24,544 Posts
              A feature request might be in order for a tv_input_option_delimiter System Setting.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                What does a text-type TV's value have to do with input options, is what I'd like to know. Using || for the delimiter in input options is fine, it's when it's used to separate the value content of the various text-type inputs that it becomes a problem. It could certainly be used for delimited types, like check boxes or radio buttons or select types. Anything that is intended to have multiple delimited content. But the text types are supposed to be plain old strings, so no delimiters should be processed.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I've posted an issue on the Revo github. https://github.com/modxcms/revolution/issues/11497

                  If I can, I'll work up the code to fix the problem - I always prefer to post an issue with the solution.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 46039
                    • 76 Posts
                    Cheers sottwell.
                      • 3749
                      • 24,544 Posts
                      This would be one way (though it might be better to set a class variable higher up in the process):

                      public function parseInputOptions($v) {
                          $a = array();
                          if(is_array($v)) return $v;
                          else if(is_resource($v)) {
                              while ($cols = mysql_fetch_row($v)) $a[] = $cols;
                          } else if (is_object($v)) {
                              $a = $v->fetchAll(PDO::FETCH_ASSOC);
                          } else { 
                             $delimiter = $this->modx->getOption('tv_input_option_delimiter', null, '||');
                             $a = explode($delimiter, $v);
                          }
                          return $a;
                      }
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting