Developer forum

Forum » Development » RenderProducts NullReferenceException

RenderProducts NullReferenceException

Jon Thorsteinsson
Reply
I've just run into a funny little quirk with the Renderer. I'm trying to add a "Products" loop to a template from a custom module.
The following code produces a NullReferenceException when calling RenderProducts:
var ps = Product.GetProductsByGroupID("my-group-id");
var r = new Renderer();
r.RenderProducts(ps, template);


But calling RenderProduct for every product in the collection works without problems:
var ps = Product.GetProductsByGroupID("my-group-id");
var r = new Renderer();
var loop = template.GetLoop("Products");
foreach (var p in ps)
{
	r.RenderProduct(p, true, loop);
	loop.CommitLoop();
}

The following code will also NOT throw an exception:
var ps = Product.GetProductsByGroupID("my-group-id");
template.GetLoop("Products");
var r = new Renderer();
r.RenderProducts(ps, template);


I've attached the call stack if you are interested.


Replies

 

You must be logged in to post in the forum