-
- 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?
Can you be more specific about the exact TV you are using? Input type? I'm not familiar with an "HTML tag" type.
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.
-
- 2,877 Posts
Quote from: sottwell at Jun 12, 2014, 06: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/
-
- 24,544 Posts
A feature request might be in order for a tv_input_option_delimiter System Setting.
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.
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.
-
- 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;
}