Hi,
I've made a PageTemplateExtender which exposes some tags, the tag "BDCartIsEmpty" is only set when the cart is empty.
From the documentation the "If Defined" tag should work on tags which have a value. If the tag has an empty (string) value or is not defined at all the If Defined should not render it's contents.
I have the following code in my PageTemplateExtender:
public class ShoppingcartInfo : Dynamicweb.PageTemplateExtender
{
public override void RenderTemplate(Dynamicweb.Templatev2.Template Template)
{
int iTotalCount = 0;
if (Dynamicweb.eCommerce.Common.Context.Cart != null)
{
//count products in the cart
foreach (Dynamicweb.eCommerce.Orders.OrderLine ordline in Dynamicweb.eCommerce.Common.Context.Cart.OrderLines)
{
try
{
if ( ordline.ProductID != null && !ordline.ProductID.Equals(""))
{
iTotalCount += Convert.ToInt32(ordline.Quantity);
}
}
catch { }
}
}
if (iTotalCount <= 0) Template.SetTag("BDCartIsEmpty", "TRUE");
Template.SetTag("BDCartTotalQuantity", iTotalCount);
Template.SetTag("BDCartTotalPrice", "");
if (Dynamicweb.eCommerce.Common.Context.Cart != null)
Template.SetTag("BDCartTotalPrice", Dynamicweb.eCommerce.Common.Context.Cart.TotalPriceFormatted);
}
}
So the "BDCartIsEmpty" tag is only set when the total count of products is zero.
In my Page template I have the following code:
<!--@BDCartIsEmpty-->
<!--@If Defined(BDCartIsEmpty)-->
Shopping Cart is empty.
<!--@EndIf(BDCartIsEmpty)-->
<!--@If Not Defined(BDCartIsEmpty)-->
Total Products: <!--@BDCartTotalQuantity-->
<br/>Total Price: <!--@BDCartTotalPrice-->
<!--@EndIf(BDCartIsEmpty)-->
For some reason it always renders the contents of the "If Not Defined" part, instead of the "If Defined" part.
Now I remember this functionality has worked in earlier versions of Dynamicweb, but I can't get it to work anymore with 18.16.2.2.
Any ideas?
Kind Regards,
Emil