Developer forum

Forum » Templates » CategoryField template tag Razor

CategoryField template tag Razor

Jonas Mersholm
Reply

How do i utilize the CategoryField template tag in Razor templates? Serializing the product loopitem shows me that it does not exist in the variable scope - although it is availabe per. the documentation ( http://templates.dynamicweb.com/eCommerce/Dynamicweb-eCommerce-template-tags/Product-Catalog/Product-detail/EcomProduct-CategoryField-ProductCategoryGroup-Field-Value.aspx )

 

Best regards.

Jonas


Replies

 
Mikkel Ricky
Reply

This should show the category field values for each product

@foreach (var product in GetLoop("Products"))
{
    @product.TemplateTags("CategoryField")
}

Best regards,
Mikkel

 
Jonas Mersholm
Reply
Sadly no.
Error compiling template "eCom/Productlist/courses.cshtml"
Line 55: 'Dynamicweb.Rendering.RazorTemplateBase.LoopItem' does not contain a definition for 'TemplateTags' and no extension method 'TemplateTags' accepting a first argument of type 'Dynamicweb.Rendering.RazorTemplateBase.LoopItem' could be found (are you missing a using directive or an assembly reference?)
 
Mikkel Ricky
Reply

Which version of Dynamicweb are you running? LoopItem.Template was introduced in March 2014.

The category fields are only rendered when actually used in the template, so try adding something like

@product.GetValue("Ecom:Product.CategoryField.Bikes.FrameSize")

to your template (using the right category and field tag names) and see if it works.

As alternatives to product.TemplateTags(), you can use 

<pre>@Newtonsoft.Json.JsonConvert.SerializeObject(product.Values, Newtonsoft.Json.Formatting.Indented)</pre>

and if that fails, try using

<pre>@foreach (var e in product.Values) {
    @: @e.Key: @e.Value
}</pre>

Best regards,
Mikkel

 

 

 
Jonas Mersholm
Reply

The solution is using version 8.3.1.17. No matter what i do, i cant get the GetValue to work.

@GetValue("Ecom:Product.CategoryField.Kurser.Dato")

 

 

I also tried outputting a full object of the template tags, without any luck on finding CategoryField either. Their not even showing up in <!--@DwTemplateTags-->  ( This might just actually be a problem on the backend. Are there any known bugs on this, on out version that you know of? )

 
Mikkel Ricky
Reply

If you're inside a loop, you have to call GetValue etc. on the loop item, e.g.

@foreach (var product in GetLoop("Products"))
{
    @product.GetValue("Ecom:Product.CategoryField.Kurser.Dato")
}

Using just @GetValue(…) will (try to) get the value from the global scope.

Best regards,
Mikkel

 

You must be logged in to post in the forum