Sitecore Asked on November 4, 2021
I have a CustomHeroViewModel class
public class CustomHeroViewModel : VariantsRenderingModel
{
public string HeroTitle { get; set; }
public string HeroDescription { get; set; }
public List<string> ImageUrl { get; set; }
}
I am using the Model field in the Rendering Variant and I am able to get HeroTitle and HeroDescription Model fields in the Rendering Variant.
ImageUrl field is the List of string. How can I loop through ImageUrl and use it in the Rendering Variant?
Has anyone done something similar to that? Any help or recommendation would be appreciated
Thanks in advance
I'm afraid this might not be possible at the moment. This feature initially was designed to work with strongly typed models so you can work around it by having:
public class CustomHeroViewModel : VariantsRenderingModel
{
public string HeroTitle { get; set; }
public string HeroDescription { get; set; }
public List<MyImage> Images { get; set; }
}
public class MyImage
{
public string SomeName { get; set; }
public string ImageUrl { get; set; }
}
and use Model Iterator variant item to iterate over the Images
property. Like this:
The other option is to override the Sitecore.XA.Foundation.RenderingVariants.Services.PropertyExtractor
and handle List<string>
.
Answered by Dawid Rutkowski on November 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP