Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pawel 22 posts 42 karma points
    Jul 16, 2012 @ 11:12
    pawel
    0

    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. 

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 16, 2012 @ 11:18
    Fuji Kusaka
    0

    Hi Pawel,

    If  you are creating nodes underneath the nodeId(1205) try to change this line from 

    var pagesToList = @Node.Descendants().OrderBy("createDate desc");

    to

      var pagesToList  = Node.Children.OrderBy("createDate descending");
  • pawel 22 posts 42 karma points
    Jul 16, 2012 @ 11:34
    pawel
    0

    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..

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 16, 2012 @ 11:44
    Fuji Kusaka
    0

    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? 

  • pawel 22 posts 42 karma points
    Jul 16, 2012 @ 12:12
    pawel
    0

    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
    }
     
    }
  • Douglas Ludlow 210 posts 366 karma points
    Jul 16, 2012 @ 17:03
    Douglas Ludlow
    0

    @pawel, use NodesById instead of NodeById, as in this example:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @try
    {
    dynamic nodes = Library.NodesById(1024, 2048, 4096);

    <ul>
    @foreach (var node in nodes)
    {
    <li><a href="@node.Url">@node.Name</a></li>
    }
    </ul>
    }
    catch (Exception e)
    {
    <!-- @e.ToString() -->
    }

     

  • pawel 22 posts 42 karma points
    Jul 28, 2012 @ 00:40
    pawel
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft