Get every parent unless DokumentType != ProductGroup
Hello,
I'm really new to razor only changed some of the existing umbraco .cshtml files so far and encountered a problem when trying to build my own templates now.
I want to create a template for a "ProductGroup", each ProductGroup can have children of Type "ProductGroup" or "Product".
In a live example it would maybe look like this:
What I know want is that when I'm on the Page for a Product, in the top example lets take the somePaperTypes-Page, I want a navigation to be displayed with the different Parent.Names and give the customer the option to klick on them as a anker-tag.
So for our example it should look like this:
expandable Items => Paper => SomePaperTypes
Als three should be anker tags of course.
Here my code I've got so far, but it only works for .Children at the moment:
@{
var groups = Model.Children;
<ul>
@foreach (var g in groups)
{
<li>
<a href="@g.Url">@g.Name =></a>
</li>
}
<li>
<a href="@Model.Url">@Model.Name</a>
</li>
</ul>
}
How can I change the code know to achieve this with the parents until the parents DocumentType is not of type "ProductGroup" ||/or "Product"?
What had me scratching my head was I was sure there was a method to get all Ancestors up to a certain level rather than from a level. There is the Up() traversing method which you can say .. Model.Content.Up(3) and go up 3 levels but this is no good for a traversa as it only returns the node at that particular levell!
I guess this might be a more succinct way of doing what you want too - also shows how to filter out document types.
Get every parent unless DokumentType != ProductGroup
Hello,
I'm really new to razor only changed some of the existing umbraco .cshtml files so far and encountered a problem when trying to build my own templates now.
I want to create a template for a "ProductGroup", each ProductGroup can have children of Type "ProductGroup" or "Product". In a live example it would maybe look like this:
expandable Items (ProductGroup) => Ink (ProductGroup) => someInkCartridges (Product) => Paper (ProductGroup) => somePaperTypes (Product)
I hope it's unterstandable.
What I know want is that when I'm on the Page for a Product, in the top example lets take the somePaperTypes-Page, I want a navigation to be displayed with the different Parent.Names and give the customer the option to klick on them as a anker-tag. So for our example it should look like this: expandable Items => Paper => SomePaperTypes Als three should be anker tags of course.
Here my code I've got so far, but it only works for .Children at the moment:
How can I change the code know to achieve this with the parents until the parents DocumentType is not of type "ProductGroup" ||/or "Product"?
Best Regards,
Chris
I think I'm following what you need..
Try this (adjusting the .Level > 1 to be relevant to your node structure):
@Steve: .OrderBy("Level") Thats what I was looking for, it now works as intendet! Thanks.
edit: final code:
What had me scratching my head was I was sure there was a method to get all Ancestors up to a certain level rather than from a level. There is the Up() traversing method which you can say .. Model.Content.Up(3) and go up 3 levels but this is no good for a traversa as it only returns the node at that particular levell!
I guess this might be a more succinct way of doing what you want too - also shows how to filter out document types.
Glad you've sorted it.
is working on a reply...