Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Oct 12, 2011 @ 22:14
    Stefan
    0

    Link to parent doctype from for-each

    Hi.

    My problem is that I can't find a way to link to GalleryItem from within the inner for-each which is creating the link to the specific gallery.

    Here's the XSLT (stripped down from everything unnesseceary):

    <xsl:variable name="Folder" select="$currentPage/GalleryItem [not(umbracoNaviHide = 1 )]"/>
    <xsl:for-each select="$Folder">
      <xsl:variable name="Images" select="umbraco.library:GetMedia(blaaahFolder, false())" />
      <xsl:for-each select="$Images">
        <a>
          <xsl:attribute name="href">
            <xsl:value-of select="umbraco.library:NiceUrl(ID of doctype GalleryItem which contains the blaaahFolder-node)" />
          </xsl:attribute>
          <xsl:attribute name="target">_self</xsl:attribute>
          <img>
            ...        
          </img>
        </a>
      </xsl:for-each>
    </xsl:for-each>

     

    The output from a copy-of is:

    <GalleryItem id="1192" parentID="1188" level="3" writerID="0" 
    creatorID="0" nodeType="1185" template="1162" sortOrder="0"
    createDate="2011-09-30T18:35:12" updateDate="2011-10-12T00:56:25"
    nodeName="Første galleri" urlName="foerste-galleri" writerName=""
    creatorName="" path="-1,1164,1188,1192" isDoc="">
    <blaaah>1207</blaaah>
    <blaaahFolder>1210</blaaahFolder>
    </GalleryItem>

    <GalleryItem id="1193" parentID="1188" level="3" writerID="0"
    creatorID="0" nodeType="1185" template="1162" sortOrder="1"
    createDate="2011-09-30T18:50:55" updateDate="2011-10-12T02:08:22"
    nodeName="Andet galleri" urlName="andet-galleri" writerName=""
    creatorName="" path="-1,1164,1188,1193" isDoc="">
    <blaaah>1200</blaaah>
    <blaaahFolder>1206</blaaahFolder>
    </GalleryItem>

    The id I need is the very first (1192 and 1193 (every gallery created with GalleryItem),
    but I can't find a way to get it right :-/

    The structure is: GalleryPage/GalleryItem
    Currentpage is GalleryPage

    The images are picked with the Media Picker for every folder. The alias for the Media Picker is blaaahFolder (sorry for the odd naming-scheme - it's just a temporary solution...).

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 12, 2011 @ 22:42
    Chriztian Steinmeier
    2

    Hi Stefan,

    You can grab that ID before going into the second loop:

    <xsl:variable name="Folder" select="$currentPage/GalleryItem[not(umbracoNaviHide = 1 )]" />
    <xsl:for-each select="$Folder">
        <xsl:variable name="Images" select="umbraco.library:GetMedia(blaaahFolder, false())" />
        <xsl:variable name="GalleryItemID" select="@id" />
        <xsl:for-each select="$Images">
            <a href="{umbraco.library:NiceUrl($GalleryItemID)}" target="_self">
                <img>
                ...         
                </img>
            </a>
        </xsl:for-each>
    </xsl:for-each>

    /Chriztian

    PS: Would be a good idea to rename the Folder variable to Folders (plural) - threw me off the track for a coouple of minutes :-)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 12, 2011 @ 22:42
    Tom Fulton
    0

    Hi,

    If I understand right, you need to get the ID of the GalleryFolder from within a nested for-each, right?

    To do this I think the only way is to store what you need in a variable outside the second for-each:

    <xsl:variable name="Folder" select="$currentPage/GalleryItem [not(umbracoNaviHide = 1 )]"/>
    <xsl:for-each select="$Folder">
      <xsl:variable name="curGalleryItemId" select="$Folder/@id"/>
      <xsl:variable name="Images" select="umbraco.library:GetMedia(blaaahFolder, false())" />
      <xsl:for-each select="$Images">
        <a>
          <xsl:attribute name="href">
            <xsl:value-of select="umbraco.library:NiceUrl($curGalleryItemId)" />
          </xsl:attribute>
          <xsl:attribute name="target">_self</xsl:attribute>
          <img>
            ...        
          </img>
        </a>
      </xsl:for-each>
    </xsl:for-each>

    Hope this helps,
    Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 12, 2011 @ 22:43
    Tom Fulton
    0

    You finally beat me :(

  • Stefan 117 posts 215 karma points
    Oct 13, 2011 @ 19:07
    Stefan
    0

    Thank you for your answers. I have now tried both, and it is still not working as I expect it to.

    This is the output from <textarea><xsl:copy-of select="$Folders" />textarea> from within the for-each statement:

    Please note that copy-of generates two textareas with the exact same content as below (there is a total of two GalleryItem entries).

    <GalleryItem id="1192" parentID="1188" level="3" writerID="0" 
    creatorID="0" nodeType="1185" template="1162" sortOrder="0"
    createDate="2011-09-30T18:35:12" updateDate="2011-10-12T00:56:25"
    nodeName="Første galleri" urlName="foerste-galleri" writerName=""
    creatorName="" path="-1,1164,1188,1192" isDoc="">
    <metaDescription></metaDescription><metaKeywords></metaKeywords>
    <bodyText> <p>Første galleri tekst.</p> </bodyText>
    <blaaah>1207</blaaah>
    <blaaahFolder>1210</blaaahFolder></GalleryItem>

    <GalleryItem id="1193" parentID="1188" level="3" writerID="0"
    creatorID="0" nodeType="1185" template="1162" sortOrder="1"
    createDate="2011-09-30T18:50:55" updateDate="2011-10-12T02:08:22"
    nodeName="Andet galleri" urlName="andet-galleri" writerName=""
    creatorName="" path="-1,1164,1188,1193" isDoc="">
    <metaDescription></metaDescription><metaKeywords></metaKeywords>
    <bodyText> <p>Andet galleri tekst.</p></bodyText>
    <blaaah>1200</blaaah>
    <blaaahFolder>1206</blaaahFolder>
    </GalleryItem>


    The result from this is that the first id is selected for both gallery entries.

    blaaah is the content (images) of a gallery entry (GalleryItem) and blaaahFolder is the selected image for the gallery listing (on currentPage).

  • Stefan 117 posts 215 karma points
    Oct 22, 2011 @ 16:25
    Stefan
    0

    Sorry guys, I think I was sleeping when trying to get this to work.

    Sometimes it just helps to get away from the problem ;-)

Please Sign in or register to post replies

Write your reply to:

Draft