[[*tv.galleryitem]]
{"gal_id":11,"gal_name":"ucaps-acc.png","gal_filename":"2/11.png","gal_description":"page accueil Ucaps","gal_mediatype":"image","gal_url":"www.commerces-sartrouville.fr","gal_createdon":"2011-09-13 16:54:53","gal_createdby":1,"gal_active":1,"gal_duration":"","gal_streamer":null,"gal_watermark_pos":"tl","gal_image_width":1074,"gal_image_height":1097,"gal_image_type":3,"gal_src":"/assets/components/gallery/files/2/11.png","gal_orig_width":1074,"gal_orig_height":1097,"gal_album":"2","gal_watermark-text":"","gal_watermark-text-position":"BL","gal_other":"","gal_rotate":"0","gal_sizer":"100","gal_cropCoords":"","gal_cropTop":0,"gal_cropRight":0,"gal_cropBottom":0,"gal_cropLeft":0} [[*tv.galleryitem:gal_id]]
<?php
// Elz 09 2011
//Using Gallery, in some catalog or portfolio cases, it could be needed to associate ONE page (modx doc) to ONE image in gallery.
//For convenience of editors, we will use the Custom TV galleryitem. This will able editors to pickup one image from any Gallery album, and eventually crop it, resize, etc.
//However this will return a tv [[galleryitem]] to be use anywhere in document that contains the image.
//If we just want to get the reference to this image in order to process it in many other ways, there's no way to get directly the id and the folder of the image wich is used for its name and file name
// its a good idea to use a parameter for tv galleryitem's name so the &gal_tv_name param is mandatory
if (!isset($gal_tv_name)) return 'no gal_tv_name';
$val = $modx->resource->getTVValue($gal_tv_name);
$explose = explode("=", $val); // to get arbitrary values of the TV in an array.
//print_r(array_values ($explose ));
// the pathes are the 7th in array
$chaine = $explose[6];
// % is a good choice to separate again
$explose = explode("%", $chaine);
// we get [0] => [1] => 2Fassets [2] => 2Fcomponents [3] => 2Fgallery [4] => 2Ffiles [5] => 2F2 [6] => 2F11.png" alt ) 2%2F11.png" alt
// the folder is in [5]
$chaine = $explose[5];
$gal_filename= substr($chaine,2);
// We create a PL for the folder name (it's relative to the components/gallery/files/ folder)
$modx->setPlaceholder('gal_foldername', $gal_filename);
// the file ( =id) is in [6]
$chaine = $explose[6];
// suppress the 9 last car
$gal_id= substr($chaine, 0, -9);
// suppress the first 2 car (2F)
$gal_id= substr($gal_id,2);
// now we creat a PL for it
$modx->setPlaceholder('gal_id', $gal_id);
return;