i am trying to interate through a media folder with mulitple child folders in it and return all the images as a list. Here is what i have, but does not seem to work. i have highlighted the part I suspect.
<xsl:template match="/"> <!-- for best results remove the lines below, and put them in the <head> of your document --> <!--Styles--> <!-- for best results remove the lines above, and put them in the <head> of your document --> <xsl:variable name="imageFolder" select="/macro/imageFolder" /> <xsl:variable name="galleryTitle" select="/macro/galleryTitle" /> <xsl:variable name="galleryDescription" select="/macro/galleryDescription" /> <xsl:variable name="imageFolderContents" select="umbraco.library:GetMedia($imageFolder/Folder/@id, 1 )"/> <div class="galleryTitle"> <xsl:if test="string($galleryTitle) != ''"> <h3><xsl:value-of select="umbraco.library:Replace($galleryTitle, '\r\n', ' ')" /></h3> </xsl:if> <xsl:if test="string($galleryDescription) != ''"> <p><xsl:value-of select="umbraco.library:Replace($galleryDescription, '\r\n', ' ')" /></p> </xsl:if> </div> <div id="thumbs" class="navigation"> <ul class="thumbs noscript">
i'm using 4.7. The method provided in your first link does not loop each folder for images. it only list the files, no matter if its image, a folder, or other types of file.
Iterate a media folder with child folders
Hi,
i am trying to interate through a media folder with mulitple child folders in it and return all the images as a list. Here is what i have, but does not seem to work. i have highlighted the part I suspect.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- for best results remove the lines below, and put them in the <head> of your document -->
<!--Styles-->
<!-- for best results remove the lines above, and put them in the <head> of your document -->
<xsl:variable name="imageFolder" select="/macro/imageFolder" />
<xsl:variable name="galleryTitle" select="/macro/galleryTitle" />
<xsl:variable name="galleryDescription" select="/macro/galleryDescription" />
<xsl:variable name="imageFolderContents" select="umbraco.library:GetMedia($imageFolder/Folder/@id, 1 )"/>
<div class="galleryTitle">
<xsl:if test="string($galleryTitle) != ''">
<h3><xsl:value-of select="umbraco.library:Replace($galleryTitle, '\r\n', ' ')" /></h3>
</xsl:if>
<xsl:if test="string($galleryDescription) != ''">
<p><xsl:value-of select="umbraco.library:Replace($galleryDescription, '\r\n', ' ')" /></p>
</xsl:if>
</div>
<div id="thumbs" class="navigation">
<ul class="thumbs noscript">
<!--interate, please check this part-------------------------------->
<xsl:for-each select="imageFolderContents/descendant-or-self::node [@nodeTypeAlias = 'Image']">
<!------------------------------------------------------------------>
<xsl:if test="string(current()/umbracoFile) != ''">
<li>
<a class="thumb">
<xsl:attribute name="href">
<xsl:text>/ImageGen.ashx?image=</xsl:text>
<xsl:value-of select="./umbracoFile" />
<xsl:text>&height=350&compression=100</xsl:text>
</xsl:attribute>
<img alt="{current()/@nodeName}">
<xsl:attribute name="src">
<xsl:text>/ImageGen.ashx?image=</xsl:text>
<xsl:value-of select="./umbracoFile" />
<xsl:text>&height=75&width=75&compression=100</xsl:text>
</xsl:attribute>
</img>
</a>
<div class="caption">
<div class="image-title"><xsl:value-of select="@nodeName"/></div>
<div class="image-desc"><xsl:value-of select="galleryImageDescription"/></div>
</div>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</div>
<div style="clear: both;"></div>
</xsl:template>
</xsl:stylesheet>
I think you should use this code :
<xsl:for-each select="$imageFolderContents/descendant-or-self::node [@nodeTypeAlias = 'Image']">
You forgot the dollor sign for the variable imageFolderContents
Hey,
What version of Umbraco are you using?
If you're using >= 4.5 then see this post http://our.umbraco.org/wiki/reference/code-snippets/listfilesfrommediafolderxslt/listing-files-from-a-media-folder-in-umbraco-45x-with-xslt
Otherwise http://our.umbraco.org/wiki/reference/code-snippets/listfilesfrommediafolderxslt
Alternatively see this package http://our.umbraco.org/projects/website-utilities/media-iterator
Rich
hi dawoe, i put in the dollar sign, but it is still not working. any further suggestion is much apppreciated. this problem has confused me for a while
hi rich green,
i'm using 4.7. The method provided in your first link does not loop each folder for images. it only list the files, no matter if its image, a folder, or other types of file.
Hi,
Did you try http://our.umbraco.org/projects/website-utilities/media-iterator?
Rich
Thanks all. After struggling for a while i finally get it working. The method is a bit dumb, but it works.
Hope it can help others.
is working on a reply...