Skip to content

Instantly share code, notes, and snippets.

@pepebe
Last active July 14, 2023 18:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepebe/25a7056d5f453ed40b14dfe7c795e4cb to your computer and use it in GitHub Desktop.
Save pepebe/25a7056d5f453ed40b14dfe7c795e4cb to your computer and use it in GitHub Desktop.
Collections - Snippetrenderer for images. Supports Media Source
<?php
// Collections Snippet Renderer
// Version: 0.1
// 2do: autoimatically retrieve assets path from media source
$row = $modx->getOption('row', $scriptProperties, '');
$value = $modx->getOption('value', $scriptProperties, '');
$column = $modx->getOption('column', $scriptProperties, '');
$imgName = $value;
$docid = $row['id'];
$tvName = substr($column, 3); // tv name without collections prefix (tv_)
$debug = print_r($scriptProperties,true);
//Add mediaSources for specifiv image TVs below
switch($tvName) {
case 'icon':
$imgPath = 'assets/tpl/img/icons/';
break;
case 'mgThumb':
$imgPath = 'assets/id/{id}/gallery/';
break;
default:
$imgPath = '';
break;
}
$find = array('{id}');
$replace = array($docid);
$imgPath = str_replace($find,$replace,$imgPath);
$thumb = $modx->runSnippet(
'pthumb'
,array(
'input' => $imgPath . $imgName
,'options' => '&w=60&h=60&zc=C'
)
);
return '<img src="' . $thumb . '" width="60"><br/>' . $imgName;
wsrnimagerenderer = function(value, metaData, record, rowIndex, colIndex, store) {
if (value != '' && value != null) {
var baseUrl = MODx.config['collections.renderer_image_path'];
/* dynamic mediasource in assets/resources/{id}/ */
var resourcePath = '../assets/resources/' + record.id + '/';
console.log(record)
if (value.indexOf('http://') === 0) {
baseUrl = '';
}
return '<div class="myimagerenderer"><img src="' + baseUrl + resourcePath + value + '" width="100"></div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment