Developer forum

Forum » Development » ProductTemplateExtender called multiple times

ProductTemplateExtender called multiple times

Anders Ebdrup
Reply

Hi,

 

I have a problem with the ProductTemplateExtender which is called multiple twice when displaying a product.

 

The ProductTemplateExtender is even called for the related products even though I have no loops on the product template. When called by the related products it does not seem to include only the template from the loop, but the whole template.

That means that I can not avoid the overhead by checking if a tag exists in the template.

 

How do I avoid this to happen?

 

Best regards, Andes


Replies

 
Jon Thorsteinsson
Reply

Usually, it is a good idea to start a product template extender with the following:

if(string.IsNullOrEmpty(Base.Request("ProductID")) || this.Product.ID != Base.Request("ProductID"))
  return;

This means that the product extender will only be executed if we are on a product page, and if we are handling the the primary product of the product page.

 

This only works on product pages. If you want to run the extender on lists, you will have to be a bit more clever.

 
Anders Ebdrup
Reply

Hi Jon,

 

Thanks for your answer. Yes, you are right about the fix, but I am searching for a more general fix and I hope Dw would be able to help with this?!

 

Best regards, Andesr

 
Nicolai Høeg Pedersen
Reply

There is no better way for the time being.

 

But it is a great idea to give you a context to react on. Will add it to wishlist.

 

BR Nicolai

 

You must be logged in to post in the forum