Get the src and alt attribute of an image in Sitecore 6?

I use the following to get, for example, the title of the current page;

Header = Sitecore.Context.Item["Header"] 

But how can I get the src url of the image field?

 PictureSrc = Sitecore.Context.Item["MyImage"] 
+6
source share
1 answer

You need to take a look at using Sitecore.Resources.Media.MediaManager to get the URL of the media library item.

Before you get there, you will get a field from this element and drop it onto FileField. When you have FileField, you can access MediaItem.

 Item item = Sitecore.Context.Item; Sitecore.Data.Fields.ImageField imgField = ((Sitecore.Data.Fields.ImageField)item.Fields["MyImage"]); string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem); string altText = imgField.Alt; 

Sitecore Media Element Link

+12
source

Source: https://habr.com/ru/post/919063/


All Articles