Developer forum
E-mail notifications
Variant Options for a Product not working in a cshtml template
Replies
You need to call GetLoop on the i variable you're iterating over:
@foreach (LoopItem i2 in i.GetLoop("VariantAvailableOptions")){
I would recommend using something other than i though and use something like variantGroup. Makes the code easier to read and issues like this easier to spot:
@foreach (var variantGroup in GetLoop("VariantGroups"))
{
@variantGroup.GetValue("Ecom:VariantGroup.Name")
<select name="@variantGroup.GetValue("Ecom:VariantGroup.ID")">
@foreach (var availableOption in variantGroup.GetLoop("VariantAvailableOptions")){
<option value="@availableOption.GetString("Ecom:VariantOption.ID")" @if(Dynamicweb.Input.FormatBoolean(availableOption.GetString("Ecom:VariantOption.Selected"))){<text>selected="selected"</text>}>@availableOption.GetString("Ecom:VariantGroups.VariantOption.Name")</option>
}
</select>
<br />
}
Cheers,
Imar
Thanks Imar well spotted, I learn not to trust completely the html/cshtml converter...
@availableOption.GetString("Ecom:VariantGroups.VariantOption.Name")
should be
@availableOption.GetString("Ecom:VariantOption.Name")
Cheers Kevin
You must be logged in to post in the forum