So I'm create a simple products page with Umbraco here is my tree;
I have a stock page which renders the following sub folders, "Lamp" and "Chairs" which will have some products under it.
For the sub folders I create a doctype with a template called "StockSubCat"
what I'm having issues with is rendering the content under the sub folders. So I want it if I click on Lamps, then all the products will show. I thought this code would work but I just get a blank page?
@foreach(var subCat in Model.Content.Children().Where(c=>c.DocumentTypeAlias == "StockSubCat"))
{
<div>@subCat.Name</div>
<ul>
@foreach(var item in subCat.Children()){
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}
Eg do you intend to write out the products on your 'stock' page, underneath each category? or at this point has the user clicked on 'Lamps' and we're now on the StockSubCat page?
(if we're executing the code in the context of the StockSubCat page, then you will get nothing, because Model.Content refers to the current page, eg Lamps, and your code only considers children of type StockSubCat, of which underneath lamps there are none...)
However if you are just trying to write out the products on the Stock homepage, in the stock template, underneath each category, then what you have 'should work'
If I've understood correctly you are on the 'Lamps' page and using the StockSubCat template, and in this context Model.Content will refer to the 'Lamps' page, and so in your foreach, you just want to loop through the children of this page that will be the products...
Display content under folders
Hello,
So I'm create a simple products page with Umbraco here is my tree;
I have a stock page which renders the following sub folders, "Lamp" and "Chairs" which will have some products under it.
For the sub folders I create a doctype with a template called "StockSubCat"
what I'm having issues with is rendering the content under the sub folders. So I want it if I click on Lamps, then all the products will show. I thought this code would work but I just get a blank page?
Hi Matt
Which template do you have the @foreach in?
Eg do you intend to write out the products on your 'stock' page, underneath each category? or at this point has the user clicked on 'Lamps' and we're now on the StockSubCat page?
(if we're executing the code in the context of the StockSubCat page, then you will get nothing, because Model.Content refers to the current page, eg Lamps, and your code only considers children of type StockSubCat, of which underneath lamps there are none...)
However if you are just trying to write out the products on the Stock homepage, in the stock template, underneath each category, then what you have 'should work'
regards
marc
Hello Marc,
Thanks for the reply.
So the @foreach is in the StockSubCat page.
By the @foreach point the user and clicked on Lamps (or chairs) and I'm trying to get all the lamps to show.
But i want it more dynamic, so depending on which "StockSubCat" page your on it will display those products.
Thanks
Matt
Hi Matt
ok, so I sort of think I understand, if you change the foreach to be:
does that give you your product listing?
If I've understood correctly you are on the 'Lamps' page and using the StockSubCat template, and in this context Model.Content will refer to the 'Lamps' page, and so in your foreach, you just want to loop through the children of this page that will be the products...
regards
marc
Aha that worked a dream, thank you :)
is working on a reply...