Developer forum

Forum » Development » "If Defined" tags using on tags from a PageTemplateExtender

"If Defined" tags using on tags from a PageTemplateExtender


Reply

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


Replies

 
Reply

I just made a small test that passed successfully in out main branch:

 

<!--@If Defined(InvalidTag)-->InvalidTag was defined.<!--@EndIf(InvalidTag)-->
<!--@If Not Defined(InvalidTag)-->InvalidTag was not defined.<!--@EndIf(InvalidTag)-->

 

What happens when you apply this to the template in question?

 

 
Reply
Sorensen wrote:

I just made a small test that passed successfully in out main branch:

 

<!--@If Defined(InvalidTag)-->InvalidTag was defined.<!--@EndIf(InvalidTag)-->
<!--@If Not Defined(InvalidTag)-->InvalidTag was not defined.<!--@EndIf(InvalidTag)-->

 

What happens when you apply this to the template in question?

 

This ofcourse renders "InvalidTag was not defined.".

 

If you create a PageTemplateExtender, and in that extender do a

 

    Template.SetTag("InvalidTag", "Is some value");

 

Then what is the result of the above template code ? 

 

Maybe some important info: I have this template code inside a PageTemplate. (A template in the  "Templates/Page" folder).

 

-Emil

 
Reply

Then If Defined would return true and the template code inside the conditional will be applied. Not setting it or setting it to an empty string would cause If Defined to return false but If Not Defined to return true.

 

Does the tag appear in the list of tags generated by !--@DwTemplateTags--?

 
Reply

Hi Lars,

 

Yes the tag appears in the DWTemplateTags list.

 

But I'm not really sure if you understand what I mean. All I'm saying is that when I set a (custom) template tag in PageTemplateExtender, and I use that tag in a Page template, the "If Defined" tags for that tag absolutely have no effect.

 

I'm going to raise a support case for it, because I'm quite sure it's a bug at the moment.

 

Kind Regards,

Emil

 
Reply

You're quite right, that was not the way I understood it:) We'll investigate the case once it reaches us.

 
Reply

Any news about this issue?

 

Regards

Thomas

 
Reply
thl@dk.columbusit.com wrote:

Any news about this issue?

 

Regards

Thomas

 

This issue has been recognized as a bug and is in the bug list.

 
Reply

Where can i find the bug list?
 

 
Reply
thl@dk.columbusit.com wrote:

Where can i find the bug list?
 


 

It's an internal bug list from which we select which bugs to solve.

 

You must be logged in to post in the forum