Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 326 posts 978 karma points MVP c-trib
    Mar 20, 2018 @ 11:03
    Owain Williams
    0

    If a child node has a child node, return value

    Hi, I currently have a content node which has a child, which also has a child. What I'm trying to get my head around is how to get the value of the media picker from the last child. e.g.

    Parent_node
     --> Child_node
           --> Child_node
                    |... uploaded image
    

    I need to get the image url from the child.

    Just now I have

    @foreach ( var item in tabItems)
    {
    do something
    }
    

    But I think I need to do something like

    @foreach (var item in tabItems)
    {
        If(item.Child.HasPropertyValue = "tabsImage")
        {
        output the image url
        }
    }
    

    is that doable?

  • Owain Williams 326 posts 978 karma points MVP c-trib
    Mar 20, 2018 @ 11:28
    Owain Williams
    0

    To try and help explain, I need to get an image url from the Green node in this tab list. So, foreach item gets the blue node information, then I need to get the image and any other information from the green node.

    Image showing structure

  • Dave 13 posts 83 karma points
    Mar 20, 2018 @ 12:09
    Dave
    0

    Hey Owain,

    if it's what I think it is...

    foreach(var node in nodes) //the blue guys
    { 
        foreach (var subnode in node.children) //the green guys 
        { 
            if(subnode.PropertyHasValue("image") 
            { 
                do something with it 
            }
        }
    }
    
  • Owain Williams 326 posts 978 karma points MVP c-trib
    Mar 20, 2018 @ 16:11
    Owain Williams
    0

    Hi Dave, Thanks but the If (subnode) always returns null.

    I think it's pretty close, if I debug and hover over subnode, I can see "Properties: Count = 6" If I expand this in debug, I can see [0], [1], [2]...

    If I expand [3] then I can see the property value "image". I just can't seem to get there to pull out the info.

    I tried if

    If(subnode.Properties[i]...
    

    But that doesn't work. I didn't expect this to be so troublesome!

    Edit:

    So, child.Properties gets me the count of 6, which is the number of items I have on the last tab, but I just need to now search those 6 items to find the PropertTypeAlias.

     if (child.Properties.PropertyHasValue("tabsImage"))
        {
            var test = "test";
        }
    

    This code gives the error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.Collections.Generic.Dictionary

Please Sign in or register to post replies

Write your reply to:

Draft