sepiariver
7/12/2015 - 10:58 PM

Retrieves thumbnail paths from a json source in MODX.

Retrieves thumbnail paths from a json source in MODX.

<?php
// Options
$input = $modx->getOption('input', $scriptProperties, '');
if (empty($input)) return;
$size = $modx->getOption('size', $scriptProperties, 'original');
$toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, '');

// Get stuff
$image = $modx->fromJSON($input);
if (!is_array($image)) return;

// Do stuff
$result = ($size === 'original') ? $image['original'] : $image['thumbs'][$size];

// Bring it
if (empty($toPlaceholder)) return $result;
$modx->setPlaceholder($toPlaceholder, $result);