On the front page of my site I would like to list sub-content from a few different folders using Razor. At the moment I use some pre-built snippets and get content from just one node:
var Node = @Model.NodeById(1205); var pagesToList = @Node.Descendants().OrderBy("createDate desc");
For some reason adding another node doesn't work:
var Node = @Model.NodeById(1205,2748);
How can I loop through a few different folders so sub-content is listed?
Hi Fuji, it is actually how you described it. this is regarding video games websites where I have 'games' folder (where are downloadable games) and 'news' folder (with news obviously). On the main page I would like to pull out short descriptions of any of these and list them in descending order. at the moment I can get either of these two but not together....
Regarding your question "is there any particular reason why you have all your nodes on the same level?"
Url are kind of clear and both things separate www.domain.com/games/ and www.domain.com/news/
I saw this from razor snippets part 5 but I can't make it work...
Your code works fine but I still had a problem with accessing deeper properties of the documents inside nodes. In the end I look throught every node (starting from Home) and use umbracoNaviHide for documents I do not want display. There are just a few of them so it works fine.
Getting content from different nodes, NodeById
Hi there,
On the front page of my site I would like to list sub-content from a few different folders using Razor. At the moment I use some pre-built snippets and get content from just one node:
var Node = @Model.NodeById(1205);
var pagesToList = @Node.Descendants().OrderBy("createDate desc");
For some reason adding another node doesn't work:
var Node = @Model.NodeById(1205,2748);
How can I loop through a few different folders so sub-content is listed?
Thanks in advance.
Hi Pawel,
If you are creating nodes underneath the nodeId(1205) try to change this line from
to
Hi Fuji, thanks a lot.
These nodes are not under each other, please have a look:
Home
- 1205 (content, content2, content3)
- 2748 (content, content2, content3)
On the front page I need to list short description of each content from these 2 nodes (and maybe later on even from 3 nodes).
Kind regards..
Hi Pawel,
I would change the structure of the content instead and have the description under the parent Node (1205.)
Something like
- Home
-- 1205
--- Content
--- Content 2
--- Content 3
is there any particular reason why you have all your nodes on the same level?
Hi Fuji, it is actually how you described it. this is regarding video games websites where I have 'games' folder (where are downloadable games) and 'news' folder (with news obviously). On the main page I would like to pull out short descriptions of any of these and list them in descending order. at the moment I can get either of these two but not together....
Regarding your question "is there any particular reason why you have all your nodes on the same level?"
Url are kind of clear and both things separate www.domain.com/games/ and www.domain.com/news/
I saw this from razor snippets part 5 but I can't make it work...
@{
var nodes = @Model.NodeById(1024,2048,4096);
foreach
(var node
in
nodes)
{
@node.Name
}
}
@pawel, use NodesById instead of NodeById, as in this example:
thanks Douglas,
Your code works fine but I still had a problem with accessing deeper properties of the documents inside nodes. In the end I look throught every node (starting from Home) and use umbracoNaviHide for documents I do not want display. There are just a few of them so it works fine.
Thanks again for your help, Pawel
is working on a reply...