Developer forum

Forum » Development » No template tags in ProductTemplateExtender

No template tags in ProductTemplateExtender

Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Im trying to make an product template extender, which is going to manipulate the value of another template tag.

    public class SalesPriceProductTemplateExtender : ProductTemplateExtender
    {
        public override void ExtendTemplate(Dynamicweb.Rendering.Template template)
        {
            const string tag = "Product.SalesPrice";

            try
            {
                var tagValue = Convert.ToInt32(template.Tags.GetTagByName("Ecom:Product.Price.Price").Value) * 2;
                template.SetTag(tag, tagValue.ToString("C"));
            }
            catch (Exception e)
            {
                template.SetTag("SalesPriceProductTemplateExtender.Debug", e.ToString());
                template.SetTag(tag, 0.ToString("C"));
            }
        }
    }

This always return 0,00 since it throw an exception. By further investigation I can see that if I do an count on "template.Tags" I get 0. So it does not look like it is fetching the template tags. Is this correct? Is this code fireing before the tags are even set? If so, how can I make an extender that fires after the tags are generated, but before the site is loaded.


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Martin

It is probably because your template is Razor.

Tags is a Collection of Rendering.Tag which is a key/value where both are strings. Razor templates are not using strings for values but the correct type instead. Therefore it runs on another collection internally in the template instance. That is called _rawTags and that collection is not available from extensibility points.

I've just made the function Template.GetRawValue public (TFS#39364) so you can use that to get the data out for calculations. Will be in the next hotfix of 9.3

BR Nicolai

Votes for this answer: 1
 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Thanks Nicolai! Is it available as a NuGet package yet, or when will it be available as a download through the portal?

 
Nicolai Pedersen
Reply

Not yet... I do not have a relase date of next hotfix.

 

You must be logged in to post in the forum