Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore versioned image not loading

I'm running Sitecore 6.5 and have a data template that has an image field and an item that's based on that template. The site had two languages.

If I use a versioned image (one item in the media library with En and Fr versions) in the En and Fr versions of the item then publish the site and switch the language in the site using query string, sc_lang=en or fr, everything changes in the page except for the image.

But if I use two different images (two items in the media library) then the correct image loads when switching between languages.

Any idea to why this happens?

Thanks T

Update

I tried using the shared option and that didn't work. I also noticed that if I just add the query parameter and hit enter, the page changes to correct language but the image doesn't until I hit the refresh button. It seems a caching issue but why does it happen only with versioned images.


1 Answers

There appears to be a bug with the <sc:image /> and FieldRenderer controls in that the generated URL doesn't have a language in the querystring.

You can try something like this:

<asp:Literal ID="image" runat="server"><img src="{0}" /></asp:Literal>

Sitecore.Resources.Media.MediaUrlOptions options = new Sitecore.Resources.Media.MediaUrlOptions
{
    Language = Sitecore.Context.Language
};
Sitecore.Data.Fields.ImageField imgField = (Sitecore.Data.Fields.ImageField)Sitecore.Context.Item.Fields["Image"];
string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem, options);
image.Text = string.Format(image.Text, url);
like image 147
Sean Kearney Avatar answered Apr 19 '26 01:04

Sean Kearney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!