Skip to content

Instantly share code, notes, and snippets.

@krismas
Created August 27, 2012 09:45
Show Gist options
  • Save krismas/3487008 to your computer and use it in GitHub Desktop.
Save krismas/3487008 to your computer and use it in GitHub Desktop.
A simple MODX output filter to convert TV code to value
<?php
/*
* checkCode : A simple MODX output filter to convert TV code to value - (c) 2012 ackwa.fr
*
* @version : 1.0.0
* @see : https://gist.github.com/gists/3487008
* @name : checkCode.php
* @author : g.noel@ackwa.fr
* @usage : myTV : First==1||Second==2||Third==3
*
* [[+myTV]] -> 1 , 2 , 3
* [[+myTV:checkCode]] -> First, Second, Third
*
* @history : 24/06/12 - 1.0.0 - Initial revision
*
* Extract Data
*/
$iPos = strpos($name, '.');
$sName = substr($name, ((false === $iPos) ? 0 : $iPos + 1));
$oTV = $modx->getObject('modTemplateVar', array('name'=> $sName));
$lOptions = explode('||', ($oTV->elements ? $oTV->elements : ''));
$sValue = '';
/*
* Convert code -> Value
*/
foreach($lOptions as $aOption) {
$lValue = explode('==', $aOption);
if ($input == $lValue[1]) {
$sValue = $lValue[0];
break;
}
}
return $sValue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment