I want to create a block Recent projects that is on my Home page which displays the last 2 published projects I have added.
I have created a node Homepage which is the root of my project, and under need a node called Projects. This contains 5 project items, 3 of them are published the others not.
On developer > Partial Views, I have created a new view called LatestProjects which I then have added on the Homepage template. I used the snippet with the Orderby on createDate.
Now, the CurrentPage variable in the foreach is now the Homepage, but how can I access the node Projects to collect the child items?
With this code you should be able to list your projects on your home page.
@{ var projects = Umbraco.ContentAtRoot().DescendantsOrSelf("umbNewsOverview").FirstOrDefault(); } <ul> @* OrderBy() takes the property to sort by and optionally order desc/asc *@
Access different node then Currentpage in Macro
Hi,
I want to create a block Recent projects that is on my Home page which displays the last 2 published projects I have added.
I have created a node Homepage which is the root of my project, and under need a node called Projects. This contains 5 project items, 3 of them are published the others not.
On developer > Partial Views, I have created a new view called LatestProjects which I then have added on the Homepage template. I used the snippet with the Orderby on createDate.
Now, the CurrentPage variable in the foreach is now the Homepage, but how can I access the node Projects to collect the child items?
Grt Mich
Hi Mich,
With this code you should be able to list your projects on your home page.
Remember to change "Projects" in the DescendantsOfSelf in the this line:
So it match your document type alias of the overview page, where you have your project items under.
I have also implemented that it only takes two of the children by using Take(2) if you change it to 3 it will display 3.
Hope this helps,
/Dennis
Hi Dennis,
Thanks for the reply!
In your code you use
Umbraco.ContentAtRoot()
does this returns the Homepage node, eg. the root?Michael
Hi Michael,
Yes it returns the root, you can read about the UmbracoHelper here including the ContentAtRoot(): http://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#ContentAtRoot%28%29
There are also a typed version of this, if you are using strongly typed version of Razor. http://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#TypedContent%28intid%29
Hope this helps,
/Dennis
is working on a reply...