$options = explode(",",$options); if (in_array($input, $options)) return true; else return false;
[[*id:inarray=`2,30,40,80`:then=`id in array!`:else=`id is not in array!`]]
if (in_array($input, $options)) return 'yes'; else return 'no'; [[*id:inarray=`2,30,40,80`:is=`yes`:then=`id in array!`:else=`id is not in array!`]]
Instead of returning a boolean true or false, try returning a numeric 1 or 0 - that should do the trick..tryed, don't worked I opened modoutputfilter.class.php placed here core/model/modx/filters. You was right about returning numeric 1 or 0 but it still don't work.
$options = explode(",",$options); return intval(in_array($input, $options));
[[!MyInArray? $docIds=`2,30,40,90`]]
<?php /* MyInArray Snippet */ $a = explode(',', $docIds); if (in_array($modx->resource->get('id'), $a)) { $output = 'something'; } else { $output = 'something else'; } return $output;
I'm not sure why that doesn't work, but why not just do all the work in a snippet. That will be a lot faster
<?php $docIds = explode(",",$options); $id = $modx->resource->get('id'); if(in_array($id, $docIds)) return true; return false;
[[*id:inarray=`2,30,40,80`:is=`1`:then=`id in array!`:else=`id is not in array!`]]
// snipped name inarray $options = explode(",",$options); return array ( [0] => intval(in_array($input,$options))); using [[*id:inarray=`2,8,100,68,...`:then=`code`:else=`code`]]
case 'then': var_dump($condition); $output = null; $conditional = join(' ', $condition); try { $m_con = @eval("return (" . $conditional . ");"); $m_con = intval($m_con); if ($m_con) { $output= $m_val; } } catch (Exception $e) {} break;
// snippet name 'testSnippet' ..... // for testing return array(0=>1); // or $condition[]=1
[[+myString:testSnippet=`someValue`:then=`code1`:else=`code2`]]
case 'then': var_dump($condition); $output = null; $conditional = join(' ', $condition); try { $m_con = @eval("return (" . $conditional . ");"); $m_con = intval($m_con); if ($m_con) { $output= $m_val; } } catch (Exception $e) {} break;
array(0){}