showing Item's images in transformations dynamically

Sonia Samimi asked on September 18, 2017 08:20

Hi guys, I've used a user control to get data and saved an image for each Item. now I try to show these Item's properties including that images via transformation. how do I get image URL dynamically? for example, image path/image file name thank you in advance

Correct Answer

Dragoljub Ilic answered on September 18, 2017 13:33

Hi Sonia,

You can try something like this:

{%
  library = SiteObjects.MediaLibraries.FirstItem;
  if(library != null)
  {
    file = library.Files.Where("FileName = 'noimage'").FirstItem;
    if(file != null)
    { 
      imageUrl = GetMediaFileDirectUrl(library.ID, file.FilePath);
    }
  } 
  return;
|(identity)GlobalAdministrator%}

This is only a dummy code. You can use better way to find library that you need (f.e. by code name), and also for specific file (f.e. file ID or any other data that you have in you transformation).

You can also move all this in custom macro method and make it easier to call it.

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.