Copied to clipboard

Flag this post as spam?

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


  • Nathan Purcell 5 posts 25 karma points
    Apr 17, 2012 @ 11:23
    Nathan Purcell
    0

    Getting all child and grandchild nodes using DAMP

    Hi all,

    I'm trying to create a usercontrol that will eventually populate a small pixel based map on the homepage of a site. Each populated pixel will will have a jQuery hover effect that will display some text information and 2 images.

    In the Umbraco back office I am using DAMP for the mulitple images selection so my current XML structure is:

    <AProject id="1260" parentID="1158" level="5" writerID="2" creatorID="1" nodeType="1156" template="1157" sortOrder="3" createDate="2012-04-04T16:00:08" updateDate="2012-04-16T11:37:58" nodeName="xxx" urlName="xxx" writerName="xxx" creatorName="xxx" path="-1,1061,1106,1111,1158,1260" isDoc="">
    <projectName>xxx1</projectName>
    <areaLocation>xxx2</areaLocation>
    <propertyImage1>
    <DAMP fullMedia="">
    <mediaItem>
    <Image id="1273" version="acb254f6-cc89-4a20-beda-b0a74fe9372b" parentID="1252" level="2" writerID="1" nodeType="1032" template="0" sortOrder="18" createDate="2012-04-04T16:54:24" updateDate="2012-04-04T16:54:24" nodeName="xxx" urlName="xxx" writerName="xxx" nodeTypeAlias="Image" path="-1,1252,1273">
    <umbracoFile></umbracoFile>

     

    The code I have is:

    var specificNode = new Node(1158);
    var childNodes = specificNode.Children;

    foreach (Node childNode in childNodes)
    {
    foreach (Property property in childNode.Properties)
    {

    }
    }

    The second foreach loop manages to get as far down as "propertyImage1", but no further. I've tried and tried to get down into the DAMP nodes and beyond but it's not working.

    I'm using Umbraco 4.7.1.

    Any help or advice would be great.

    Thanks.

  • Grant Thomas 291 posts 324 karma points
    Apr 17, 2012 @ 12:05
    Grant Thomas
    0

    The `DAMP` node has child nodes which won't be considered children of the `AProject` node. If you refactored your loops into a recursive function you could carry on through the depths of other nodes, though. Such as...

    void IterateChildren(Node node) {
      foreach (Node child in node.Children) {
        foreach (Property property in child.Properties) {
          //do something with the properties of this node
        }
        //do this over again for the children node
        IterateChildren(child);
      }
    }

    It's likely you actually want to return something, which would entail tailoring this to your needs, obviously.

  • Nathan Purcell 5 posts 25 karma points
    Sep 21, 2012 @ 13:10
    Nathan Purcell
    0

    In XSLT:

    <xsl:variable name="allImages" select="$currentPage/propertyImage1/DAMP[@fullMedia]/mediaItem"/>
      
        <ul>
            <xsl:for-each select="$allImages/Image">
                
                <xsl:variable name="imageLocation" select="current()/umbracoFile" />
                <xsl:variable name="fileSize" select="current()/umbracoBytes" />
                
                <li>
                  <a href = "{$imageLocation}">
                  <img src="{$imageLocation}" alt="{$fileSize}" width="150" />
                  </a>
                </li>
                
              </xsl:for-each>
              <!-- end for each -->                  
          <div class = "clearing">&nbsp;</div>                  
        </ul>  
     
Please Sign in or register to post replies

Write your reply to:

Draft