Module Builder Media/image fields - Custom Interface widget:

Posted by Community Admin on 04-Aug-2018 18:16

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

All Replies

Posted by Community Admin on 06-Nov-2012 00:00

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.

Posted by Community Admin on 06-Nov-2012 00:00

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.

Posted by Community Admin on 15-Mar-2014 00:00

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

This thread is closed