Module Builder Media/image fields - Custom Interface widget: Example? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Module Builder Media/image fields - Custom Interface widget: Example?

  • Module Builder Media/image fields - Custom Interface widget: Example?
  • I have created custom widgets for other Module Builder data types, but I can't seem to figure out how to do so for image fields?     I have seen examples that return the URL of a single image, but the module builder image field seems to requires an array of Guids or some other object.
  • I don't have much time to write out a great example, but it will require something along these lines. This code is pretty rough and not optimized best practice. This is just intended to give you some idea what would be needed to get the url string for an image.

    Assuming you have a collection of data from Sitefinity that includes image links...

    foreach (var item in collection)
      // Get a link to an image in a collection
       // Replace "YourImageField" with whatever field stores the images
      var links = (ContentLink[])item.GetValue("YourImageField");
       // Only getting the first image... 
      ContentLink imageLink = links.FirstOrDefault();
     
      // Take the content link above and retrieve the image from the library
      LibrariesManager libManager = LibrariesManager.GetManager();
      var image = libManager.GetImage(img.ChildItemId);
     
      string ImageUrl = image.Url;

    I can provide a better example later if you provide some more specifics regarding your need.
  • Hi Dan Sorensen,

     

    I am following steps given above but I got stuck on line below

    var image = libManager.GetImage(img.ChildItemId);

    in above line you wrote img which is not declared secondly you didn't usedimageLink any where

    ContentLink imageLink = links.FirstOrDefault();

     

    Please tel me how to implement