We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36604
    • 268 Posts
    Hi can someone tell me how to automaticaly get, for a page, the id (into a PL if possible) of a Gallery image choosen through the Custom Gallery imageTV.

    (I wanna manipulate this image but don't want to just display it with
    [[*tv.galleryitem]] 
    )

    I set the output format of the custom TV imageitem to TEXT instead of galleryitem, so we can see the text contained into the tv:
    this is:
    {"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} 


    I tried
    [[*tv.galleryitem:gal_id]]


    Need output modifier ?

    Thank you
      • 36604
      • 268 Posts
      I made a snippet to deal with this custom TV.

      There's probably a more efficient coding, I'm not areal PHP coder...
      I made it with no knowledge of the "inside of this TV".

      <?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;


      Now I need to uses this inside a Getressources call. to get the references to the image and manipulate it instead of displaying it at full scalle in the tplrow.

      I really need some help for this.

      Thank you [ed. note: elz064 last edited this post 15 years ago.]