Hello MODX-ers,
I am trying to find if a value is in a multi select template variable and output code based on that value.
Here is an example page I am working on:
http://trucreator.com/shop/things-you-wear/boom-bap.html
I
am using MIGX and have a tv called "product-gender" that accepts "Girls" and "Guys" with the output set to delimited, outputting "Girls,Guys". I want to display the Girls/Guys radio buttons only if that option is available.
I initially attempted to use the 'inarray' output filter with 'if' like this:
[[!if?
&subject=`Guys`
&operator=`inarray`
&operand=`[[*product-gender]]`
&then=`<button type="button" value="Guys" class="btn" data-toggle="button">Guys</button>`
]]
but to no avail... So I went the snippet route and created a snippet that accepts the tv like this:
Snippet Call:
[[tv-lookup?
&tv=`[[*product-gender]]`
&value=`Guys`
]]
Snippet Code (currently being output on the sample page):
$array = explode(',', $tv);
//$array = array("Girls","Guys");
if (in_array($value, $array)) {
echo("Found in Array");
}else{
echo("Not Found in Array");
};
echo "
TV: ";
echo $tv;
echo "
Array: ";
print_r($array);
echo "
Value: ";
print_r($value);
echo "
Array 0: ";
echo $array[0];
echo "
Array 1: ";
echo $array[1];
echo "
";
What seems weird is that when I switch the commented out $array sections then the if statement passes and everything else seems identical.
So, my questions are:
A. Is there something fundamentally wrong in the way I am going about solving this problem in the first place? Suggestions welcome
B. Is there some reason why in_array won't work on the exploded tv array but will on the manually created one (currently commented out)?
C. Is MIGX to blame, or possibly involved since I am not outputting the tv as text?
Thanks!
Roger
[ed. note: [email protected] last edited this post 14 years, 6 months ago.]