1

I am able to get the Sitecore media link by using the Sitecore Scriban Embedded method as follows:

<img src="{{sc_follow i_article 'Thumbnail'| sc_medialink}}">

But, not sure how to get the value of the Alt field value of the Sitecore Media item using the Sitecore Scriban Embedded functions.

1 Answer 1

2

You can use {{i_datasource.Image}} or {{ i_item.Image}} to get image src and alt. Here .Image is the image type field name, in your case, it seems like Thumbnail. so, it should be {{i_datasource.Thumbnail}}

Scriban code should be something like this:

<div class="some-class">
{{i_datasource.Image}}
</div>

The output will be:

<div class="some-class">
<img src="/-/media/Project/Sites/image-name.png" alt="image-alt">
</div>

Refer to this documentation for more details: https://doc.sitecore.com/xp/en/developers/sxa/102/sitecore-experience-accelerator/scriban-templates.html

3
  • Yes it works, Thanks @Raman Oct 31, 2022 at 8:42
  • 1
    Just posting the further in addition to this helpful answer that if you want only src and alt attributes then use it like src "{{i_article.Thumbnail.media_url}}" alt="{{i_article.Thumbnail.alt}}", otherwise it will add height and width attribute that can not be suitable in the mobile view. Oct 31, 2022 at 10:03
  • As @PrashantTomar indicated, this is not the true answer as it adds height and width. Thank you Prashant for posting the actual answer in your comment but I wish you had posted it and marked it as the correct answer.
    – Michael
    Jan 12 at 13:04

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.