Generating A partial View of items from another page
Hello all,
I understand how to generate a view of child items on a page.
But how can i generate a view of items on a page from another pages child nodes eg. On the Home page i want a list of 4 of the most recent portfolio items from inside:
Ok, generally the standard approach is to have 1 root node per website (you can have multiple sites/languages) then all other pages are children of that root node. You will find all code snippets etc expect this structure.
You can select only 4 items by using the .Take(n) method, e.g.
@foreach (var page in CurrentPage.DescendantOrSelf("portfolioDocType").Children.Where("Visible").Take(4))
You may want to add a OrderBy() in there before the .Take()
Generating A partial View of items from another page
Hello all,
I understand how to generate a view of child items on a page.
But how can i generate a view of items on a page from another pages child nodes eg. On the Home page i want a list of 4 of the most recent portfolio items from inside:
Portfolo
Something like this on your homepage:
Where "portfolioDocType" is the document type alias of your "Portfolio" page, hopefully it's unique and only used by that node.
Thats very useful.
Is there a way to select the first four?
Or a specific number?
The Portfolio Doc type i use is only use by that node and is called Portfolio.
I used that exact code and it doesnt render anything when i pass HTML into the {} after the call.
Is that the correct syntax?
My content layout is as follows:
Home
About
Portfolio
Hi James,
Ok, generally the standard approach is to have 1 root node per website (you can have multiple sites/languages) then all other pages are children of that root node. You will find all code snippets etc expect this structure.
You can select only 4 items by using the .Take(n) method, e.g.
You may want to add a OrderBy() in there before the .Take()
Jeavon
I now have all my content nodes inside the home content node.
I have allowed child node types.
I run that code exactly as it is written then with my "Portfolio" doc type and it isntpulling anything through.
Any ideas?
My documents types are all listed. And i have set my homepage doc type to allow all 3 of the child nodes.
My content tab now looks like
Home
Can you check the document type alias of Portfolio is exactly "portfolioDocType" and also try running this code on your homepage?
I have double checked it and the Doc type "Portfolio" now has the alias of "portfolioDocType" My code references that too.
This code is located on the home template undertneath my master.
Still not outputting anything .
Kind regards.
I cant see any syntax errors in visual studio either.
Ok, then this should be
DescendantOrSelf("portfolioDocType")
?Hmm, seems it doesn't work fully dynamic.
This should work ok:
Or bizarrely this also works...
Hi James,
Did you get this working?
Jeavon
is working on a reply...