1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Converting Lstring ContentItem Data from Custom Module to HTML Image

Converting Lstring ContentItem Data from Custom Module to HTML Image

4 posts, 1 answered
  1. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    18 Feb 2013
    Link to this post

    I have a custom module with a long Text field, named Logo.   It contains a single Image and other HTML.  I want to display the logo image on the page, so I just assign the value to a literal, ("myCompany" is of type DynamicContent).

    var logo = myCompany.GetValue<Lstring>("Logo").Value;
            litLogo.Text = logo;

    The result displays this HTML on the page:

    <img src="[images|OpenAccessDataProvider]421d54cc-469b-6485-baf1-ff00000f0a6a" title="godfrey-logo">

    Any help is appreciated.

    Coty

  2. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    18 Feb 2013 in reply to Coty
    Link to this post

    Going to make this a two part question, the first above.  Basically how do you pull a long Text field from a custom module and displaying as HTML so that all images show up that are embedded?

    Second - in looking at my custom module I added a Media field named logo that holds the company logo instead.  The block below works to pull this data.  Is this the correct/most efficient way to pull an image from a custom module?

    //Get image from custom module
    LibrariesManager libraryManager = LibrariesManager.GetManager();
    var logos = myPartner.GetValue<Telerik.Sitefinity.Model.ContentLinks.ContentLink[]>("Logo");
    foreach (var logoLink in logos)
    {
        var image = libraryManager.GetImage(logoLink.ChildItemId);
        //add image to page
        litLogo.Text = "<img src='" + image.Url + "' /img>";
    }

    Thanks!

    Coty

  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Coty
    Link to this post

    Hi Coty,

    Regarding your questions:

    Long Text field
    I think you should use the LinkParser to get the right html from your text field. You can use it like this:

    var parser = LinkParser.ResolveLinks("CONTENT");

    It has some more overloads, if you need them.

    Getting an image
    Your code is fine. You could make it a bit smaller like this:

    var contentLinks = (ContentLink[])item.GetValue("myPartner");
    var imageContentLink = contentLinks.Count() > 1 ? contentLinks.OrderBy(x => x.Ordinal).First() : contentLinks.FirstOrDefault();
    litLogo.Text = string.Format("<img src='{0}' />", imageContentLink.ChildItemId.GetImage().MediaUrl);

    Kind regards,
    Daniel

    Answered
  4. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Sorry, for this last code to work, you will need an extension method.
    Just put this method in a static class, named e.g. 'Extensions':

    public static Image GetImage(this Guid imageId) {
       var manager = LibrariesManager.GetManager();
       return (imageId != Guid.Empty) ? manager.GetImage(imageId) : null;
    }

    Kind regards,
    Daniel

4 posts, 1 answered