Copied to clipboard

Flag this post as spam?

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


  • Peter Schermers 112 posts 134 karma points
    Nov 15, 2012 @ 16:55
    Peter Schermers
    0

    Get children from 'NodeById'

    I am sure this question has been asked before, but I can't find any solution on Google or this forum. :-(
    So I'll just post it here ;-)

    Since I didn't get any replies on my last question, I decided to build this website in an easier way (that is, easier for me as starter ;-)

    Okay, here's the situation:

    I have a parent node called 'Products', where subnodes can be created beneath it by the user, to create product categories. Each of these new subnodes has an Embedded Content-field which the user can fill in.

    Here's the big question: how can I display the content of these Embedded Content-fields in a dynamic way,
    so that the user can keep creating subpages which will all be taken into the foreach loop?


    Thanks in advance!

  • Tommy Turkijevic 7 posts 28 karma points
    Nov 15, 2012 @ 20:28
    Tommy Turkijevic
    0

    Hi Peter,

    Is your parent node at the root level ?
    If it is a node you loading you can try to access .GetChildrenAsList and then do a foreach loop over the children and then access
    the content field of the node.

    As an example:

    foreach(var itm in myNode.ChildrenAsList
    {
      @itm.YourContextField

    }

    When i have a RootLevel node I use uQuery to access them and choose by DocumentType. Like this:

    @{
       
         var latestNews = umbraco
                        .uQuery
                        .GetNode(-1)
                        .GetDescendantNodesByType("NewsItem")
                        .OrderByDescending(t => t.CreateDate)
                        .Take(3)
                        .ToList();   
       
                       
                        foreach(var n in latestNews)
                        {
                        
                         <div class="span3">
                            <a href="@n.NiceUrl"><h5>@n.GetProperty("newsTitle").Value</h5></a><span>@n.CreateDate.ToShortDateString()</span><p>@teaser</p>
                        </div>  
                        }

    }

     

    Did this help ?

    /Tommy

  • Peter Schermers 112 posts 134 karma points
    Nov 16, 2012 @ 10:39
    Peter Schermers
    0

    Hi Tommy,

    Thanks for your response!

    To be honest, I decided to give my first piece of code a try once more, and got it almost working.
    You can find it here:

    http://our.umbraco.org/forum/developers/razor/36146-Combining-%27pagination%27-and-%27embedded-content%27-in-Umbraco

    Would you do me a favor and take a look at my question here?
    Because, if I could get this question answered, I would be more helped than the simplified question I asked above.
    I almost got it working, it's just one line of code missing, I guess.

    thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft