Developer forum

Forum » Development » How do I get the productid in a ProductListTemplateExtender?

How do I get the productid in a ProductListTemplateExtender?

Kim Søjborg Pedersen
Reply
Here are some example code to explain my need. I need to extend the productlisttemplate with a special tag and call the getColors with the current productid. I there a way to do this?

public class ExtendColorsToProductListTemplate : ProductListTemplateExtender
    {
        public override void ExtendTemplate(Dynamicweb.Templatev2.Template template)
        {
                     
            template.SetTag("Colors", getColors(?));
        }
  
  private string getColors(string productId)
  {
   //Based on some logic and the product id for the current product in the list, I need to get som information here......
   
  }
    }

Replies

 
Morten Bengtson
Reply
I'm not sure I understand what you need.

If you need to extend the rendering of each product in your product list, you should use a ProductTemplateExtender.

If you actually need to extend the rendering of a separate product list on the same page as your current product, then you can get the ProductID from the querystring with Dynamicweb.Base.Request("ProductID")

BR.
Morten
 
Kim Søjborg Pedersen
Reply
 It is the productlist I want to extend with my tag, so I think the ProductListTemplateExtender must be the one.

I try to explain it more clealy.

Im on a page with a groupid in the querystring. On the page all products in that group is listed. Foreach of the products I want to extend with my own tag. The content of that custom tag is specific for each of those products and thats why i need the productid.
 
Morten Bengtson
Reply
 
 Foreach of the products I want to extend with my own tag

Then I think you need to use a ProductTemplateExtender - it will be called for each product in the list.

It is a template extender for products (in whatever template they are rendered). It is not an extender only for the product details template.
 
Kim Søjborg Pedersen
Reply
Okay thank you for that, but I still need a way to get the productid?
 
Morten Bengtson
Reply
This post has been marked as an answer
Try this...

public override void ExtendTemplate(Dynamicweb.Templatev2.Template template)
{                      
    template.SetTag("Colors", getColors(Product.ID));
}
  
private string getColors(string productId)
{
    //Based on some logic and the product id for the current product in the list, I need to get som information here......   
}

Votes for this answer: 0

 

You must be logged in to post in the forum