Get value of the Image description

From the above image. How I could get the image description?

Litium version: 7.6.1

This is one way of getting it, if it’s a product image.

        var image = productModel.BaseProduct.Fields.GetValue<IList<Guid>>(SystemFieldDefinitionConstants.Images).First();
        var imageFile = _fileService.Get(image);
        var imageModel = image.MapTo<ImageModel>();

        if (imageModel != null)
        {
            imageModel.Alt = imageFile.Fields.GetValue<string>(SystemFieldDefinitionConstants.Description, _cultureInfo);
        }

This is probably the code you are looking for:

_fileService.Get(image).Fields.GetValue< string>(SystemFieldDefinitionConstants.Description, CultureInfo.CurrentUICulture);

In litium 8, the description field works as alt text for images :partying_face:

2 Likes

Thank you very much. This is what I was looking for :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.