If I want to render the image url in a data-attribute (lets assume the Image Field is called TeaserImage) I can render the Media URL by $(TeaserImage). So far so good.

Now I have a reference field for my image because I need the Alt text from the media item. For the data-scr attribute I need the media url of the Image Field I have passed through. $(Item) does not work. Should be something like $(this)?

How can I get the actual item that I have passed through?

enter image description here

1 Answer 1


I don't think you can do this ootb... unless you are on 9.3 and are able to use Scriban.

There is a workaround though - but it's a dirty hack and maybe not upgrade-proof. I used to have an issue where I had to use a data attribute in a section to get a value from a referenced item - which also didn't work as those attributes work on text fields only.

After some discussion with Support and the Sxa team, we found a solution by overriding a part of the RenderVariantField pipeline. In our case the variant was a section, so we had to override RenderSection. Seems to be the same in your case (looking at the image).

You can override the GetAttributeTokenValue function (which expects a fieldname and item) to implement your needed logic and then return to the base logic. If I understand correctly you should "invent" some name as you do not need an actual field value.

More info on my blog: https://ggullentops.blogspot.com/2018/10/using-tokens-in-sitecore-sxa-variant.html

  • Thank you I will have a look into it.
    – Bgl86
    Dec 5, 2019 at 13:59

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.