Copied to clipboard

Flag this post as spam?

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


  • Frost 5 posts 25 karma points
    Nov 02, 2011 @ 06:24
    Frost
    0

    Show 1 thumbnail only on each image folder

    Hello, ive been wanting to show 1 thumbnail only on each image folder on my gallery.

    Currently im using this Xslt to populate my page with all the folder images and it works well

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:umbraco.library="urn:umbraco.library"
            exclude-result-prefixes="umbraco.library">

            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

            <xsl:param name="currentPage" />
              

            
            <!-- Grab QueryString parameter (if present) -->
            <xsl:variable name="imgId" select="umbraco.library:RequestQueryString('img')" />

              
              <xsl:template match="/">
            <!-- Process the picturesFolder (if one is specified) -->
            <xsl:apply-templates select="$currentPage/mediaFolderId[normalize-space()]" />
              </xsl:template>
            
    <!-- Template for the property -->
    <xsl:template match="mediaFolderId">
            <xsl:choose>
                    <xsl:when test="$imgId">
                            <!-- Process a single Image -->
                            <xsl:variable name="mediaImage" select="umbraco.library:GetMedia($imgId, false())" />
                            <xsl:apply-templates select="$mediaImage[not(error)]" mode="single" />
                    </xsl:when>
                    <xsl:otherwise>
                            <!-- Process the folder -->
                            <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia(., true())" />
                            <xsl:apply-templates select="$mediaFolder[not(error)]" />
                    </xsl:otherwise>
            </xsl:choose>
    </xsl:template
            
            <!-- Template for the root folder -->
            <xsl:template match="Folder">
                    <h3><xsl:value-of select="@nodeName" /></h3>
                    <ul>
                      <!-- Render all Images, Files or (sub-)Folders in this folder -->
                            <xsl:apply-templates select="Image | Folder" />
                    </ul>
            </xsl:template>

            <!-- Template for an Image (thumbnail linked to fullsize view of image)-->
            <xsl:template match="Image">
              <xsl:variable name="ext" select="concat('.', umbracoExtension)" />
             <href="{umbraco.library:NiceUrl($currentPage/@id)}?img={@id}">
                <img src="{concat(substring-before(umbracoFile, $ext), '_thumb', $ext)}" alt="{@nodeName}" />
              </a>
            </xsl:template>

            <!-- Template for displaying single Image -->
            <xsl:template match="Image" mode="single">
                    <div class="image">
                          <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
                    </div>
            </xsl:template>

    </xsl:stylesheet>

    This is the part where the folder images are populated, it currently show all the images of each folder

     <!-- Template for an Image (thumbnail linked to fullsize view of image)-->
            <xsl:template match="Image">
              <xsl:variable name="ext" select="concat('.', umbracoExtension)" />
             <href="{umbraco.library:NiceUrl($currentPage/@id)}?img={@id}">
                <img src="{concat(substring-before(umbracoFile, $ext), '_thumb', $ext)}" alt="{@nodeName}" />
              </a>
            </xsl:template>

    Now, what i wanted is instead of show all the images of each folder - i just want it to show just the first image thumbnail of the folder.

    Apologies if this is a dumb question, but ive been stuck with this for some hours already and im not that adept with xlst, thanks much in advance.

     

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 02, 2011 @ 08:22
    Chriztian Steinmeier
    1

    Hi Frost,

    It's pretty straight forward oonce you know it - you already have the template that does the actual rendering, you just need to tell the processor to only render Images or the first Image in a Folder - you do that by changing a single line in the "Folder" template:

    <ul>
        <!-- Render all Images, Files or (sub-)Folders in this folder -->
        <xsl:apply-templates select="Image | Folder/Image[1]" />
    </ul>

    See - you ask for all Image elements in the root Folder and any Image that's the first in a subfolder.

    Let me know if it needs tweaking...

    /Chriztian

  • Frost 5 posts 25 karma points
    Nov 02, 2011 @ 08:27
    Frost
    0

    Hi Chriztian,

    Man you are the best, that did the trick.

    I should really know more about xlst.

    Thank you much.


Please Sign in or register to post replies

Write your reply to:

Draft