Question re rendering parts from a customer controller

Topics: General, Writing modules
Oct 23, 2012 at 11:12 AM

I currently have a ContentItem that has a part called NavItemPart.

Everything works fine and I am able to use projections and it renders fine.

My problem is my part has a field called Brand, and i need to get a list of all the content items that have brand 'x'.

I have created a custom controller called BrandController, and a view along with a route so i can get to it using ~/brands/{brandname}.

So far so good, all works. But when my view gets called how do i get it to return a list of my parts using my already defined part cshtml ? And would it, or can it, still call the driver for the part (I have some logic in there for calculating the customer price)

I don't really want to create loads of projections for each brand, a little puzzled and some wise words of wisdom from the experts would be most grateful.

I have had a little look around but can't seem to find any examples of this, though I have got it to use my NavItem.cshtml file, but it musnt be using the driver, and I'm not sure how I would get it to return a list of them.

Thanks

Roland

Developer
Oct 23, 2012 at 4:07 PM

Did you know you can access your Field like this?

((dynamic)contentItem).NavItemPart.Brand.Value (Value may vary between fields...)

Doing this you could loop around and weed out the ones you want?

If you need to pass the brand back and filter on this, then when you create a Filter you can add a filter on the Brand field, and then use the URL tokens to do an ==

Hope that helps. Nick

Oct 25, 2012 at 12:37 PM

Thanks - just what I was looking for.