Reputation: 122
I have a rendering which it's data source is an image from the Media Library in sitecore.
How can i map this image as glass mapper image field.
using Glass.Mapper.Sc.Fields;
public class FullWidthImage
{
public virtual Image Image { get; }
}
Upvotes: 1
Views: 1720
Reputation: 2635
You can't map the image item to a class with an image field (your item is at class-level, not at field-level). The class (FullWidthImage) maps to the datasource's item (template). If your item is an Image, the fields will be Src, Alt and so on.. To accomplish the mapping to the class you want (FullWidthImage), you will need to create a template which includes an Image field (called 'Image' as in your class, unless you would specify the name in the class). This is what SitecoreClimber already suggested as a better practice.
When this is done, you can use the GetDataSourceItem
function from the GlassController
to fetch the datasource and cast to your type.
Upvotes: 1
Reputation: 4118
What do you want to achieve is a bad practice. My suggestion is to create your data source item that will have an Image field. Using your approach you can't edit inline that image using Experience Editor.
Upvotes: 3