Change the src of an image using an asset image programmatically for each section
Answered
Posted Nov 08, 2021
Hello,
I am trying to change programmatically the image displayed in the section page depending of the section name.
I would like to use image in assets.
I tried to rebuild the helper but I doesn't seem to work:
let imgSrc = "{{asset 'img-section-" + section.name.replace(/ /g,"-").toLowerCase() + ".png'}}"
imgWide.src = imgSrc
I tried to put the asset as background in css but it seems like the helper is not compile:
let imgName = "$asset-img-section-" + section.name.replace(/ /g,"-").toLowerCase() + "-jpg"
imgWide.style.background = "no-repeat center/100% url(" + imgName + ")"
Do you have any idea to do this? Do I miss something?
Thanks for your help
Paul
1
2
2 comments
Tipene Hughes
Again, feel free to reach out with any questions!
Tipene
0
Tipene Hughes
Thanks for reaching out and sorry for the delay in getting back to you!
One way you can achieve the outcome you're looking for is by using the
#is
helper:https://developer.zendesk.com/documentation/help_center/help-center-templates/helpers/#is-helper
You can add multiple #is helpers to your section_page.hbs file to conditionally render the desired image depending on the section name. Here's an example of how you could implement that:
I hope this helps! Feel free to reach out with any questions.
Tipene
0
Sign in to leave a comment.