Hi,
I built an extension for LoopItems that gets the product image tags and returns the first one that's not empty. Though it's pretty simple and basic it does not work because the tags are not rendered in the ProductList template (I am guessing for performance reasons, DW does not render tags that are not requested). In other words, if I simply output the images tags in the template (somewhere - even within a comment), then it starts to work.
Is there any way around this? If not I will have to change my method to take the tags as parameters, but I wanted to avoid that.
Here's how I use my extension
@foreach (var product in GetLoop("Products"))
{
var image = product.GetImagePath();
...
}
Here's the code for it (which lives in a compiled dll)
public static string GetImagePath( this RazorTemplateBase<RazorTemplateModel<Template>>.LoopItem product, ImagePathOrder imagePathOrder = ImagePathOrder.SmallMediumLarge)
{
switch (imagePathOrder) { case ImagePathOrder.SmallMediumLarge: return new[] { product.GetString("Ecom:Product.ImageSmall.Clean"), product.GetString("Ecom:Product.ImageMedium.Clean"), product.GetString("Ecom:Product.ImageLarge.Clean"), GetProductImagePattern(product.GetString("Ecom:Product.Number"), product.GetString("Ecom:Product:Field.ImageFileNamingPart.Value.Clean")) }.GetFirstAvailableString(); case ImagePathOrder.LargeMediumSmall: return new[] { product.GetString("Ecom:Product.ImageLarge.Clean"), product.GetString("Ecom:Product.ImageMedium.Clean"), product.GetString("Ecom:Product.ImageSmall.Clean"), GetProductImagePattern(product.GetString("Ecom:Product.Number"), product.GetString("Ecom:Product:Field.ImageFileNamingPart.Value.Clean")) }.GetFirstAvailableString(); default: return GetProductImagePattern(product.GetString("Ecom:Product.Number"), product.GetString("Ecom:Product:Field.ImageFileNamingPart.Value.Clean")); }
}
Best Regards,
Nuno Aguiar