Skip to content

Instantly share code, notes, and snippets.

@sashabeep
Last active June 30, 2023 12:18
Show Gist options
  • Save sashabeep/048e59ce2a001387e2d257f5f4d696cc to your computer and use it in GitHub Desktop.
Save sashabeep/048e59ce2a001387e2d257f5f4d696cc to your computer and use it in GitHub Desktop.
List template variable modx evo
<?php
/*usage: [[ list? &tvname=`param` &class=`myclass` &name=`myname` &docid=`N` ]] */
$doc = isset($docid) ? $docid : $modx->documentIdentifier;
$class = isset($class) ? $class : "";
$name = isset($name) ? $name : "";
$input = $modx->getTemplateVar($tvname,'*',$doc)['value'];
$vals = explode("||",$input);
if(!empty($vals)){
$out = '<select name="'.$name.'" class="'.$class.'">';
foreach($vals as $k=>$v){
$out.='<option value="'.$v.'">'.$v.'</option>';
}
$out.= '</select>';
return($out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment