Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Dec 13, 2011 @ 14:06
    Nicky Christensen
    0

    List children by a nodeId from a content picker?

    Hey...

    Im currently listing children from a specific ID, however, I want the the id to come from a folder, i've chosen from a content picker - My currently script looks like this:

    @*
    LIST CHILDREN BY Chosen nodeId from content picker
    =================================
    *@

    @inherits umbraco.MacroEngines.DynamicNodeContext

    <div class="rotator">
      @foreach (var item in @Model.NodeById(1065).Children.Where("Visible"))
      {
        <figure data-img='@item.Media("backgroundImage", "umbracoFile")' class="show">
          <figcaption>@item.sliderText</figcaption>
        </figure>
      }
    </div>

    The NodeById(1065) should be replaced with a id from the folder i've chosen with the content picker...

    I've tried this, but this doens't work:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    var bgImgFolder = @Model.AncestorOfSelf.backImages;

    <div class="rotator">

      @foreach (var item in @Model.NodeById(bgImgFolder).Children.Where("Visible"))

      {

        <figure data-img='@item.Media("backgroundImage", "umbracoFile")' class="show">

          <figcaption>@item.sliderText</figcaption>

        </figure>

      }

    </div>

    Any help would be greatly appreciated... Thx

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Dec 13, 2011 @ 14:58
    Dan Diplo
    0

    What is the value of bgImgFolder you are getting? It should be an int.

    Also, it looks like you are trying to get all images from a media folder rather than a content folder? In that case you should use Model.MediaById(). In fact, in Umbraco 4.71 you really should use Library.NodeById() and Library.MediaById().

  • Nicky Christensen 76 posts 166 karma points
    Dec 13, 2011 @ 15:13
    Nicky Christensen
    0

    The problem is that bgImgFolder is empty, so im not getting a value :(

    Nope, it is items in a specific folder in the content the i want to loop...

    So i need the Id of the folder i've chosen with the content picker at the template(item)

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 13, 2011 @ 15:37
    Sebastiaan Janssen
    0

    Looks like you're trying to the the bgImgFolder in a recursive way, this should work for you:

    Model.GetPropertyValue("backImages", true)

    The "true" operator there says to look up in the tree recursively, it should find the first non-null, non-empty "backImages" property.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Dec 13, 2011 @ 17:55
    Dan Diplo
    1

    Seb, I've sometimes found Model.GetPropertyValue doesn't always work as expected with recursive properties - see http://umbraco.codeplex.com/workitem/30607. The way around I've found is to do the following:

    dynamic node = CurrentModel.AncestorsOrSelf().Items
    .Where(x => x.HasValue("backImages")).LastOrDefault();

    That gets you a reference to the node, you can then access it's property as normal eg.

    var id = node.backImages
  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 13, 2011 @ 18:34
    Sebastiaan Janssen
    0

    Thanks Dan, that is some horriblke code. Let's hope 4.7.1.1 comes out soon!

  • Adi 17 posts 36 karma points
    Dec 16, 2011 @ 15:30
    Adi
    0

    This works for me

    @using System;
    @using System.Web;
    @using umbraco.NodeFactory;

    @if (Model.Children.Where("Visible").Count() > 0)
       {
           <table class='subpages' cellpadding='0' cellspacing='0'>
            <tr><th>In this section</th></tr>
            <tr><td style='padding-left: 10px;'><ul class='sb_menu'>
             @foreach (var subpage in Model.Children.Where("Visible"))
             {
                <li><a href="@subpage.Url">@subpage.Name</a></li>
             }
             </ul></td></tr>
          </table>
        }
     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies