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 02, 2011 @ 23:40
    Stefan
    0

    Problems

    Hi.

    I'm creating a gallery which will list all images from a media folder. I can't figure out how to get the images following the new XSLT schema. I have a working gallery on Umbraco < 4.5 which I have tried to follow, but with no luck.

    I have written this as a reference:

      <xsl:value-of select="local-name($currentPage)" />
      <br />
      <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)"/>
      <br />
      <xsl:value-of select="$currentPage/galleryFolder" />


    Which shows the following when rendered on the page:

    GalleryItem
    /galleri/foerste-galleri.aspx
    1176


    I have tried many things to get the images to show, and this is the approch I'm working on now:

      <xsl:variable name="docFolder" select="$currentPage/galleryFolder"/>

      <xsl:if test="$currentPage/galleryFolder != 0">
        <xsl:for-each select="umbraco.library:GetMedia($docFolder, 'true')/* [@isDoc]">
          .....
        </xsl:for-each>
      </xsl:if>


    Please help - or all my hair will soon be gone...

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 02, 2011 @ 23:55
    Chriztian Steinmeier
    0

    Hi Stefan,

    Media items don't get the isDoc attribute, so that's your nightmare item right there - here's something that should work:

    <xsl:template match="/">
        <xsl:if test="normalize-space($currentPage/galleryFolder)">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., true())" />
            <xsl:for-each select="$mediaNode[not(error)]/Image">
                <!-- ... -->
            </xsl:for-each>
        </xsl:if>
    </xsl:template>

    /Chriztian 

  • Stefan 117 posts 215 karma points
    Oct 03, 2011 @ 00:37
    Stefan
    0

    Thank you for your reply.

    But, unfortunately I still can't get it to work :-/
    - can you be a little more precise? Maybe you can construct an example of a link to each image from the galleryFolder?

    Another question. Will an Alias of a docType conflict with the property Alias of another docType if they are the same?

    Thank you in advance!

  • wolulcmit 357 posts 693 karma points
    Oct 03, 2011 @ 02:46
    wolulcmit
    0

    Hey Stefan,
    What's not working for you in Chriztians's example?

    what does the following give you?

    <xsl:variable name="img" select="$currentPage/galleryFolder"/>
      <xsl:if test="$img!=''">
                <img>
                    <xsl:attribute name="src"><xsl:value-of select="umbraco.library:GetMedia($img,true())/umbracoFile" /></xsl:attribute>
                    <xsl:attribute name="alt"><xsl:value-of select="umbraco.library:GetMedia($img,true())/@nodeName" /></xsl:attribute>
                </img>
      </xsl:if>

    or assuming that the node you mentioned (1176) is a media folder
    this should do the trick


    <xsl:variable name="mediaFolder" select="$currentPage/galleryFolder"/>
      <xsl:if test="$mediaFolder!=''">
        <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($mediaFolder, true())" />
        <xsl:for-each select="$mediaItems/Image">
                <img>
                    <xsl:attribute name="src"><xsl:value-of select="umbracoFile" /></xsl:attribute>
                    <xsl:attribute name="alt"><xsl:value-of select="@nodeName" /></xsl:attribute>
                </img>
        </xsl:for-each>
      </xsl:if>

    you should probably follow Chriztian's example though as it's got better error checking going on with normalize-space and [not(error)] I'm not familiar with those myself so haven't included them in my example

    cheers,

    - Tim

  • Stefan 117 posts 215 karma points
    Oct 03, 2011 @ 12:13
    Stefan
    0

    I have now tried to follow your examples. The last one didn't render anything.

    Your first example rendered the name of the folder in which the images are stored.
    Example (from media section):

    Media
    --Galleri
    ---- Gallery 1
    -------- Image 1
    -------- Image 2
    -------- Image 3
    -------- Image 4

    Your example would render "Gallery 1".

    I think I have mixed something up when it comes to using my Document Types and so on regarding the gallery.

    Example of my content tree:

    Content
    -- Homepage
    ---- Gallery (document type GalleryFolder)
    -------- Gallery 1 (document type GalleryItem)

    The GalleryItem document type has the Gallery 1 media folder selected.
    The Alias for the mediapicker (document type GalleryItem) is imgFolder (has just changed that to ensure it wont conflict with other names/alias)

    I can't really make any sense of it right now - considering to remove all and start over :-/

  • wolulcmit 357 posts 693 karma points
    Oct 03, 2011 @ 17:49
    wolulcmit
    1

    Hi again Stefan,

    maybe your xml cache needs refreshing? right-click on content and choose republish entire site
    or anternatively you can do it via this url http://YOURDOMAIN/Umbraco/dialogs/republish.aspx?xml=true

    in that second example I gave, make sure that the getmedia call uses true() rather than 'true'
    Also make sure you save and publish any nodes once you've changed any doctype or property aliases.

    <xsl:variablename="mediaFolder"select="$currentPage/imgFolder"/>
      <xsl:iftest="$mediaFolder!=''">
        <xsl:variablename="mediaItems"select="umbraco.library:GetMedia($mediaFolder, true())"/>
    <textarea><xsl:copy-of select="$mediaItems" /></textarea>
        <xsl:for-eachselect="$mediaItems/Image">
                <img>
                    <xsl:attributename="src"><xsl:value-ofselect="umbracoFile"/></xsl:attribute>
                    <xsl:attributename="alt"><xsl:value-ofselect="@nodeName"/></xsl:attribute>
                </img>
        </xsl:for-each>
      </xsl:if>

    does the above give you anything in the <textarea></textarea> tag?
    I think you're on the right track, so bear with us, I'm sure we'll have the problem cracked soon


    - Tim

  • Stefan 117 posts 215 karma points
    Oct 03, 2011 @ 23:06
    Stefan
    0

    OMG, so much trouble corrected with such a simple fix...!

    At first I wasn't getting any results with the code-snippet from your previous post. I then changed the $currentPage/imgFolder to another Alias which selects a particular image from the gallery to be shown on the page which lists all galleries. Then I saw the copy-of info about that particular image.

    I then refreshed the cache which partially solved my problem, since I then was getting results on one gallery-page.
    I might have added the images after I changed the Alias which caused the rest of the gallery images not to show?

    Do you follow a particular scheme when naming Aliases, document types and so on? I think that have been the source to my trouble from the very beginning, since I found a document type called GalleryFolder (which lists all galleries) and an Alias on another document type (GalleryItem) called galleryFolder.

Please Sign in or register to post replies

Write your reply to:

Draft