3

If I were mapping a Link type field, I can override the default URL options like this.

[SitecoreField(UrlOptions = SitecoreInfoUrlOptions.AlwaysIncludeServerUrl)]
public Link ThisIsALink { get; set; }

If I were using fluent configuration, it would look like this.

Map(x =>
{
    x.Field(field => field.ThisIsALink)
     .Configuration.UrlOptions = SitecoreInfoUrlOptions.AlwaysIncludeServerUrl;
});

How can I do the same with an Image type field?

2 Answers 2

4

Looks like is a know issue https://github.com/mikeedwards83/Glass.Mapper/issues/111 ; I suggest you to open an issue ticket on GlassMapper github;

https://github.com/mikeedwards83/Glass.Mapper/issues

Maybe @MichaelEdwars will fix it in future versions.

enter image description here

1

Still an issue unfortunately. I just needed the image URL so had to go down the route of implementing an extension method. Something like below

public static string GetAbsoluteUrl(this Image value, ISitecoreContext sitecoreContext = null)
{
    if (value == null || value.MediaId == Guid.Empty)
    {
        return string.Empty;
    }

    var mediaItem = (sitecoreContext ?? new SitecoreContext()).Database.GetItem(new ID(value.MediaId));
    if (mediaItem == null)
    {
        return string.Empty;
    }

    var options = MediaUrlOptions.Empty;
    options.AlwaysIncludeServerUrl = true;
    return MediaManager.GetMediaUrl(new MediaItem(mediaItem), options);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.