Developer forum

Forum » Development » SetTag functionality in Razor

SetTag functionality in Razor

Richard Briefjes
Reply

We use settag, tag.count() and LoopExists("LoopName") in the template extenders, so we can use specific part of the code for a template. This work good when we use a html template, but with a Razor template we don't anything. The razor template doesn't have anything when we use the SetTag functionality and the Tag.Count() = 0. Is there a work around for this?

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Dynamicweb.eCommerce.Frontend;
using Dynamicweb.eCommerce.Orders;
using System.Web;

namespace CustomOrderTemplateExtender
{
    public class CustomOrderTemplateExtender : OrderTemplateExtender
    {
        public override void ExtendTemplate(Dynamicweb.Rendering.Template template)
        {
            if (this.RenderingState == TemplateExtenderRenderingState.Before)
            {
                Order order = this.Order;
                try
                {
                    if (template.Tags.Count() > 0)
                    {
                        if (template.LoopExists("CustomLoop")) {
                           //The rest of the code
                        }
                    }

                    template.SetTag("CustomPrice", "0.00");
                }
            }
        }
    }
}

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Richard

Not sure I understand the use of Tags.Count? Why do you add that conditional?

Razor does not use the tag collection as it is not a key/value string replace like HTML templates, but a dictionary with object values available when executing the Razor template parser.

BR Nicolai

 

You must be logged in to post in the forum