Last active
August 29, 2015 14:11
-
-
Save Beagon/0c6e28b61ba5305c1b85 to your computer and use it in GitHub Desktop.
[MODX] Converts an array of TV options to a JSON &where string, for use in snippets such as Rowboat or getResources.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * TV2JSON | |
| * | |
| * Generates a JSON sting to be used in snippets like Rowboat and getResources | |
| * | |
| * Author: Robin Rijkeboer <Robin@qaraqter.nl> | |
| * | |
| * PROPERTIES: | |
| * | |
| * &templateVariable required | |
| * &delimiter optional. Default: , | |
| * | |
| * USAGE: | |
| * | |
| * [[!TV2JSON? &templateVariable=`[[*SuperAwesomeTemplateVariable]]`]] | |
| * | |
| */ | |
| $TV = $modx->getOption('templateVariable', $scriptProperties); | |
| $delimiter = $modx->getOption('delimiter', $scriptProperties, ","); | |
| if (empty($TV)) | |
| { | |
| return ""; | |
| } | |
| $splitTV = explode($delimiter, $TV); | |
| $count = 0; | |
| $string = ""; | |
| foreach ($splitTV as $value) { | |
| if($count == 0) { | |
| $string .= '{"id":"' . $value; | |
| $count++; | |
| } else { | |
| $string .= ',"OR:id":"' . $value . '"'; | |
| } | |
| } | |
| $string .= "}"; | |
| return $string; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment