1

Is there a way to make a datasource template that will have a treelist where you can choose the image or video (it can be two seperate treelists) and the display those images or videos in the code (.cshtml file)?

2 Answers 2

1

As mentioned in the answer from Sumit you can have a TreeList in the template that has its source in the media folder so you can select images or videos.

To fetch this data you can use Scriban. Take a look at https://doc.sitecore.com/xp/en/developers/sxa/102/sitecore-experience-accelerator/the-embedded-functions-for-the-scriban-template.html for the available extensions. You will need sc_followmany to loop through the selected items (images) from the TreeList. And for each of those (media)items you can use sc_medialink to get the media url. This will be something like:

{{ for i_image in (sc_followmany i_datasource "Images") }}
  <img src="{{ sc_medialink i_image }}"/>
{{ end }}

ps: didn't test the Scriban code, just combined some examples here - so it might be slightly different but it should give you an idea

1

You can create a TreeList field and point the source in the template where your image or video exists in the Sitecore Tree.

And to read the items from Treelist, you can use this link and find all the details to read the value in code.

https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-manager/access-checklist,-multilist,-treelist,-and-treelistex-fields.html

I think this will give you all the details of an Image and Video item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.