Hey. The issue, when I try too put an @TemplateTags() in a product loop, it breaks the page, returning an ServerError page. With no templatetags the page works fine.
Ive tried putting the Template tag all over the template, it breaks no matter how i implement it, but if I put it in another template, as the Master.cshtml, all is well.
When I say the page works fine, that is not entirely true, since the VariantCombinations loop does not render, but the VariantGroup loop does...
The code:
@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using CustomCode.Functions;
@MasterPageFile("Paragraph.cshtml")
@{
var maxSize = 28;
var userName = GetGlobalValue("Global:Extranet.UserName");
var cartPageID = GetGlobalValue("Global:eCommerce.CartPageID");
var productCatalogPageID = Ecom.GetPageIdByLink(Pageview.Area.Item["ProductCatalogPage"].ToString());
var myPageID = Ecom.GetPageIdByLink(Pageview.Area.Item["MyPage"].ToString());
var title = GetString("Item.Title");
var products = GetLoop("Item.Products");
var allowWishList = (bool)Pageview.Area.Item["AllowWishList"];
var allowProductCompare = (bool)Pageview.Area.Item["AllowProductCompare"];
}
<h2 class="tt_uppercase m_bottom_10 color_dark heading1 animate_ftr t_xs_align_c">@title</h2>
@if (productCatalogPageID == 0)
{
<div class="alert_box r_corners warning m_bottom_15">
<i class="fa fa-exclamation-circle"></i>
@Translate("FeaturedProducts.NoProductCatalogPageID", "You need to define a 'Product Catalog Page ID' in admin.")
</div>
}
@if (myPageID == 0)
{
<div class="alert_box r_corners warning m_bottom_15">
<i class="fa fa-exclamation-circle"></i>
@Translate("FeaturedProducts.NoMyPageID", "You need to define a 'My Page ID' in admin.")
</div>
}
@if (products != null && products.Count > 0)
{
<section class="products_container category_grid">
@*@if (productCatalogPageID == 0)
{
<div class="alert_box r_corners warning m_bottom_15" style="padding:2px 10px 1px 10px;">@Translate("FeaturedProducts.NoProductCatalogPageID", "You need to define a 'Product Catalog Page ID' in admin.")</div>
}
@if (myPageID == 0)
{
<div class="alert_box r_corners warning m_bottom_15" style="padding:2px 10px 1px 10px;">@Translate("FeaturedProducts.NoMyPageID", "You need to define a 'My Page ID' in admin.")</div>
}*@
@foreach (LoopItem i in products)
{
var id = i.GetString("Ecom:Product.ID");
var number = i.GetString("Ecom:Product.Number");
var name = i.GetString("Ecom:Product.Name");
var imageCustom = i.GetString("Product.ImageCustom");
var languageID = i.GetString("Ecom:Product.LanguageID");
//var price = i.GetString("Ecom:Product.Price");
var compareID = i.GetString("Ecom:Product.CompareID");
var linkGroupClean = i.GetString("Ecom:Product.LinkGroup.Clean");
var dbPrice = i.GetDouble("Ecom:Product.DBPrice");
var salesPrice = dbPrice;
var wishListPageID = Ecom.GetPageIdByLink(Pageview.Area.Item["WishList"].ToString());
var variantCount = i.GetInteger("Ecom:Product.VariantCount");
var variantGroups = i.GetLoop("VariantGroups");
var allowBuy = i.GetBoolean("Product.AllowBuy");
var isInCart = i.GetBoolean("Ecom:Product.IsInCart");
var productLink = string.Format("/Default.aspx?ID={0}&ProductID={1}", productCatalogPageID, id);
var popup = string.Format("#{0}_popup", ((!string.IsNullOrEmpty(userName)) ? "blank" : "login"));
var url = string.Format("/Default.aspx?id={0}&ProductID={1}&LanguageID={2}", wishListPageID, id, languageID);
var addCompare = string.Format("add_compare_{0}", compareID.Replace("$", "_"));
var removeCompare = string.Format("remove_compare_{0}", compareID.Replace("$", "_"));
<div class="product_item w_xs_full no-transition @(isInCart ? "in_cart" : string.Empty)" data-productno="@number">
@i.TemplateTags()
<figure class="r_corners photoframe type_2 t_align_c tr_all_hover shadow relative">
<a class="d_block relative wrapper pp_wrap m_bottom_15" href='@productLink' style="height:150px; text-align:center; line-height:150px;">
<img style="margin:auto; vertical-align:middle;" src='@Ecom.GetImage(imageCustom, height:250, width:250, placeholderText:Translate("Ecom.NoImage", "No image"), placeholderTextSize: 30)' class="tr_all_hover" alt="@name" />
</a>
<figcaption>
<p style="text-transform:uppercase; font-size:11px;">@Translate("Ecom.ProductNumber"): @id</p>
<h5 class="m_bottom_10" title='@name' style="height:34px;">
<a href='@productLink'>@Ecom.Wrap(name, 50)</a>
</h5>
<div class="clearfix">
<div class="f_left" style="width:50%; text-align:right;">
<div style="text-transform:uppercase; font-size:11px; margin:4px 30px 0 0;">@Translate("Ecom.SalesPrice")</div>
</div>
<div class="f_size_large f_right m_bottom_15 t_align_r" style="width:50%;">
<b>@salesPrice.ToString("C")</b>
</div>
</div>
<!-- VARIANTER -->
@if (variantCount > 0)
{
<div class="variants my-3 clearfix">
@foreach (LoopItem vg in variantGroups)
{
<label class="variant-select-label f_left m-2">@vg.GetString("Ecom:VariantGroup.Label")</label>
<select id="SelectVariantId" class="form-control js-variant-select mx-2 @((vg.GetString("Ecom:VariantGroup.ID") == "FRG") ? "js-variant-color" : string.Empty) ">
@foreach (LoopItem vao in vg.GetLoop("VariantAvailableOptions"))
{
<option @(vao.GetBoolean("Ecom:VariantOption.Selected") ? "selected" : string.Empty) value="@vao.GetString("Ecom:VariantOption.ID")">@vao.GetString("Ecom:VariantOption.Name")</option>
}
</select>
}
</div>
foreach (LoopItem vc in i.GetLoop("VariantCombinations"))
{
<table class="js-variant-price collapse description_table mx-2 width-100" id='@vc.GetValue("Ecom:VariantCombination.VariantID")'>
<tr class="m_top_5">
<td style="text-transform:uppercase;">@Translate("Ecom.ListIncl")</td>
<td class="f_size_large m_bottom_15 t_align_r"><span class="">@salesPrice.ToString("C")</span></td>
</tr>
<tr class="t_align_r NetPrice">
<td>@Translate("Ecom:Price"): </td>
<td>@vc.GetString("Ecom:Product.Price.PriceWithoutVATFormatted")</td>
</tr>
<tr class="t_align_r">
<td>@Translate("Ecom:Stock"): </td>
<td>@vc.GetDouble("Ecom:VariantCombination.Product.Stock")</td>
</tr>
<tr class="t_align_r">
<td class="t_align_r" align="right" colspan="2">
<form method="post" role="form">
<input type="hidden" name="ID" value="@i.GetValue("Ecom:Product:Page.ID")" />
<input te="hidden" name="ProductID" value="@i.GetValue("Ecom:Product.ID")" />
<input type="hidden" name="VariantID" value="@vc.GetValue("Ecom:VariantCombination.VariantID")" />
<input type="number" name="Quantity" value="1" style="width:67px;" />
<input type="hidden" name="CartCmd" value="add" />
<button type="submit" style="height:37px;" class="button_type_4 bg_scheme_color r_corners tr_all_hover color_light mw_0">@Translate("Ecom:AddToBakset")</button>
</form>
</td>
</tr>
</table>
}
}
<!-- Varianter slutt-->
@if (allowBuy && variantCount == 0)
{
<div class="clearfix">
<input type="text" class="r_corners type_2 t_align_c add_to_basket_quantity @(!isInCart ? string.Empty : "debug")" style="width:50px; height:34px;" value="1" data-productno="@id" />
<button onclick="BlockUI(); window.location.href = '/Default.aspx?ID=@cartPageID'; return false;" class="button_type_4 bg_light_color_1 r_corners tr_all_hover color_dark mw_0 m_bottom_15 added_to_basket @(isInCart ? string.Empty : "debug")" data-productno="@id"><i style="font-size:16px;" class="fa fa-check"></i> @Translate("Ecom.AddedToCart")</button>
<button style="height:31px;" class="button_type_4 bg_scheme_color r_corners tr_all_hover color_light mw_0 m_bottom_15 add_to_basket @(isInCart ? "debug" : string.Empty)" data-productno="@id">@Translate("Ecom.AddToCart")</button>
</div>
}
<div class="clearfix m_bottom_5">
<ul class="horizontal_list d_inline_b l_width_divider">
@if (allowWishList == true)
{
<li title="" class="m_right_15 m_md_right_0 tooltip_container" data-popup="#blank_popup" data-url='@url'><a class="color_dark" href=""><i class="fa fa-heart-o m_right_5"></i> @Translate("Ecom.AddToWishlist")</a><span class="tooltip_type_2 bottom tr_all_hover r_corners f_size_small color_dark d_block">@Translate("Ecom.AddToWishList.Tooltip")</span><span class="d_mxs_none"> | </span></li>
}
@if (allowProductCompare == true)
{
<li title="" class="@addCompare tooltip_container" style="margin:0;"><a class="color_dark" href="javascript:Compare.add('@compareID', '@name', '@linkGroupClean')"><i class="fa fa-files-o m_right_5"></i> @Translate("Ecom.AddToCompare")</a><span class="tooltip_type_2 bottom tr_all_hover r_corners f_size_small color_dark d_block">@Translate("Ecom.AddToCompare.Tooltip")</span></li>
<li title="" class="@removeCompare tooltip_container" style="display:none; margin:0;"><a href="javascript:Compare.remove('@compareID', true)"><i class="fa fa-files-o m_right_5"></i> @Translate("Ecom.Compare.Remove")</a><span class="tooltip_type_2 bottom tr_all_hover r_corners f_size_small color_dark d_block">@Translate("Ecom.RemoveFromCompare.Tooltip")</span></li>
}
</ul>
</div>
</figcaption>
</figure>
</div>
}
</section>
}
else
{
<div class="alert_box r_corners info m_bottom_15">
<i class="fa fa-info-circle"></i>
@Translate("FeaturedProducts.NoProducts", "No products")
</div>
}