Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Dec 18, 2012 @ 02:13
    John C Scott
    0

    recursively finding multi node tree picker parent property if none selected on current page

     

    I'm reprising an idea I did previously with an embedded content control.

    http://our.umbraco.org/projects/backoffice-extensions/embedded-content/general/26558-recursive-embedded-content

    This time I am using a uComponents "Multi Node Tree Picker" (mntp)

    The basic idea is that the document type inherits from a "public" type. So the document type inheritance looks like:

    + Public   [property:logo-picker]
      + - Section
         + - Article

    And so all section and article document types inherit a "logo-picker" document property from the public property. The logo picker is a data type base on the mntp and allows you to select logos from a specific "folder/node/mediaType" in the media library. Then my site is organised into sections and articles, and sections can contain articles, or deeper sections, and articles can contain sub sections too. 

    EG:
    + Section : Social Media Products
      - + Article : Twitter Facebook
      - + Section : Integration 
      - - + Article: Open ID
      - - + Article: API and over sharing
    + Section: CMS
      - +Article: Umbraco
      - - + Article: Team Lotus
      - - + Article: Lexus Marketing Hub
      - - + Article: Rolls Royce
      - - + Article: RichardBridgland.com
      - +Article: Ektron
      - - + Article: TalkToFrank
      - - + Article: City-Index

    Every document type has the logo picker property containing either none or some logos picked. If none are picked then the setting of the parent or it's parent. So if the logo-picker has no picks set for a document node it inherits the setting of it's parent's node.

    I've approached this by using a call-template:

        <xsl:param name="currentPage"/>
        <xsl:variable name="recursiveLogoNodeId">
            <xsl:call-template name="IterateLogo">
                <xsl:with-param name="node" select="$currentPage" />
            </xsl:call-template>
        </xsl:variable>
        <xsl:template name="IterateLogo">
            <xsl:param name="node" />
            <xsl:choose>
                <xsl:when test="$node/@level = 1 or $node/logoPicker [count(MultiNodePicker/nodeId) &gt; 0 ]">
                    <xsl:value-of select="$node/@id" />
                </xsl:when>
                <xsl:otherwise>     
          <xsl:call-template name="IterateLogo">
                        <xsl:with-param name="node" select="$node/parent::*" />
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>

    so this then recursively calls itself until finds a node which has a count of at least one nodeId in the logo-picker

    and then processes this node

    and so follows the starting match="/" template

        <xsl:template match="/">
            <xsl:if test="$currentPage/logoHide">
            <xsl:variable name="recursiveLogoNode" select="umbraco.library:GetXmlNodeById($recursiveLogoNodeId)" />
            <h4><xsl:value-of select="$recursiveLogoNode/logoLabel"/> </h4>
            <xsl:for-each select="$recursiveLogoNode/logoPicker/MultiNodePicker/nodeId">
                        <a href="etc...">
                            <img src="{$mediaNode/umbracoFile}" alt="{@nodeName}" />

    however this doesn't work all the time

    i have one specific example that isn't working

    a simplified copy of the xml document config for that page is here

    showing a couple of articles inside a section and the articles have no logos selected in the picker and the containing parent has the sections but in this case it doesn't work correctly

     

    <Section id="1060" parentID="1054" level="2" nodeName="Open Source Software" isDoc="">
          <Article id="1261" parentID="1060" level="3" nodeName="Search Solutions" isDoc="">
            <contentHeading>Search Solutions</contentHeading>
            <contentFirstPara><![CDATA[<p>Our open source search solutions use the Lucene... etc ]]></contentFirstPara>
            <contentBody><![CDATA[<p>We offer our search solution under a comprehensive web based interface to allow control of the following.</p>ETC ]]></contentBody>
            <umbraco301MovedPermanently />
            <logoPicker><![CDATA[]]></logoPicker>
            <logoHide>0</logoHide>
          </Article>
          <Article id="1146" parentID="1060" level="3" nodeName="Content Management Systems" isDoc="">
            <contentHeading>Content Management Systems</contentHeading>
            <contentFirstPara><![CDATA[<p>We know we have the open source products ETC.</p>]]></contentFirstPara>
            <contentBody><![CDATA[<p>We have delivered dozens of CMS-driven ETC</p>]]></contentBody>
            <umbraco301MovedPermanently />
            <logoPicker><![CDATA[]]></logoPicker>
            <logoHide>0</logoHide>
          </Article>
          <sectionImage />
          <sectionIcon>1118</sectionIcon>
          <contentHeading>Open Source Software</contentHeading>
          <contentFirstPara><![CDATA[<p>Much has been reported about Open Source technologies and now, with such a focus on ETC.</p>]]></contentFirstPara>
          <contentBody><![CDATA[<p>These are the questions we are most frequently ETC</p>]]></contentBody>
          <metaHideNav><![CDATA[]]></metaHideNav>
          <logoLabel>Open Source customers include</logoLabel>
          <umbraco301MovedPermanently />
          <logoPicker>
            <MultiNodePicker type="media">
              <nodeId>1119</nodeId>
              <nodeId>1255</nodeId>
              <nodeId>1259</nodeId>
            </MultiNodePicker>
          </logoPicker>
          <logoHide>0</logoHide>
        </Section>

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 18, 2012 @ 09:17
    Chriztian Steinmeier
    100

    Hi John,

    First of all - The recursive lookup you're doing is technically OK - I can't see why it would fail at times, but it shouldn't be necessary to do a recursive template here - if you create a match template for logoPicker you should be able to use apply-templates like this:

    <xsl:template match="/">
        <xsl:if test="$currentPage[logoHide = 1]">
            <!-- Find the nearest ancestor (or myself) that has any logos picked -->
            <xsl:variable name="recursiveLogoNode" select="$currentPage/ancestor-or-self::*[normalize-space(logoPicker//nodeId)][1]" />
            <h4><xsl:value-of select="$recursiveLogoNode/logoLabel"/></h4>
    
            <!-- Process the logos picked on this -->
            <xsl:apply-templates select="$recursiveLogoNode/logoPicker" />
    
            <!-- more stuff -->
    
    </xsl:template>
    
    <!-- Template for the logoPicker property -->
    <xsl:template match="logoPicker">
        <xsl:for-each select="MultiPicker/nodeId">
            <!-- Do the usual GetImage() stuff -->
        </xsl:for-each>
    </xsl:template>

     

    Note: Be careful with the logoHide property check - you should always check for the expected value - the way you're checking will probably always return true because you're actually just checking if the logoHide property is there. Maybe this is part of the reason you're getting weird results? 

    /Chriztian

     

     

  • John C Scott 473 posts 1183 karma points
    Dec 18, 2012 @ 13:50
    John C Scott
    0

    OOH thanks Chriztian amazing :) i'll try that

  • John C Scott 473 posts 1183 karma points
    Dec 20, 2012 @ 13:39
    John C Scott
    0

    I like your solution much more and I've changed it to this.

    But I can't believe what an idiotic mistake I just made, that's had me foxed for over a month.

    An old classic chestnut. It did not appear some of the time because one template did not have the macro call on it.

    Shoot me now :-$

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 20, 2012 @ 14:01
    Chriztian Steinmeier
    0

    Ha :)

    - it just goes to show that such a clown move *does* happen from time to time, and it's good to be reminded about it so you're aware of at least one extra point of failure to examine :-)

    Have a merry Christmas John,

    /Chriztian 

  • John C Scott 473 posts 1183 karma points
    Dec 20, 2012 @ 14:15
    John C Scott
    0

    aaah the tears of a clown :)

    merry christmas to you too

Please Sign in or register to post replies

Write your reply to:

Draft