You can use the count() function to count the number of items, ex:
<xsl:variable name="myFolder" select="umbraco.library:GetMedia(1117,true())" /> Total items in folder: <xsl:value-of select="count($myFolder/* [@id])"/>
Note, I added [@id] to the xpath to make sure it only finds nodes that have an id attribute, otherwise I think it will pick up properties from your folder as well -- since there is no @isDoc in media.
Counting number of media in media folder
Can someone point out how to count the number of Items present in a folder in media section for a paging to work?
Hi Fuji,
You can use the count() function to count the number of items, ex:
Note, I added [@id] to the xpath to make sure it only finds nodes that have an id attribute, otherwise I think it will pick up properties from your folder as well -- since there is no @isDoc in media.
-Tom
Hi Tom,
This is how i proceeded am using a mediaCurrent here to pick the media folder from a template. Here the paging is showing only 1 instead.
<xsl:variable name="mediaFolder" select="/macro/imgFiles"/>
<xsl:variable name="itemsToDisplay" select="10"/>
<xsl:variable name="numberOfItems" select="count($mediaFolder/*[@id])"/>
<xsl:variable name="jump" select="$itemsToDisplay * $pageNumber" />
<xsl:variable name="pageNumber">
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('page') = ''">
<xsl:value-of select="1"/>
xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
xsl:otherwise>
xsl:choose>
xsl:variable>
<xsl:template match="/">
<ul>
<xsl:if test="$mediaFolder">
<xsl:variable name="mediaItems" select="umbraco.library:GetMedia($mediaFolder/*/@id, 'true')" />
<xsl:for-each select="$mediaItems/Image">
<xsl:if test="position() <= $jump and position() >= ($jump - $itemsToDisplay)">
<li>
<a href="{concat(substring-before(umbracoFile,'.'),'_slideshow.jpg')}">
<img src="{concat(substring-before(umbracoFile,'.'),'_thumbnail.jpg')}" />
a>
li>
xsl:if>
xsl:for-each>
xsl:if>
ul>
<ul id="paging">
<xsl:if test="$pageNumber > 1">
<li>
<a href="?page={$pageNumber -1}#page">previousa>
li>
xsl:if>
<xsl:call-template name="for.loop">
<xsl:with-param name="i">1xsl:with-param>
<xsl:with-param name="count" select="ceiling($numberOfItems div $itemsToDisplay)">xsl:with-param>
xsl:call-template>
<xsl:if test="(($pageNumber) * $itemsToDisplay) < ($numberOfItems)">
<li>
<a href="?page={$pageNumber+1}#page">nexta>
li>
xsl:if>
ul>
xsl:template>
<xsl:template name="for.loop">
<xsl:param name="i"/>
<xsl:param name="count"/>
<xsl:if test="$i <=$count">
<xsl:if test="$pageNumber!= $i">
<li>
<a href="?page={$i}#page"><xsl:value-of select="$i" />a>
li>
xsl:if>
<xsl:if test="$pageNumber = $i">
<li>
<xsl:value-of select="$i"/>
li>
xsl:if>
<xsl:call-template name="for.loop">
<xsl:with-param name="i" select="$i + 1" />
<xsl:with-param name="count" select="$count">
xsl:with-param>
xsl:call-template>
xsl:if>
xsl:template>
The problem is mediaCurrent doesn't include the child items, only the current selected media.
To fix you'll need to use GetMedia to get a reference to that media item and include its children:
Note I moved your mediaItems variable up so you can re-use it for both calls. Also you should change 'true' to true()
-Tom
Still cant get the paging to work though. I must have missed something here...
I see you added $numImg but I think your code is still referencing $numberOfItems in the for.loop template call.
Yup but still not doing it...
Paste your updated code, I'll see if I can take a look
Try this instead. numImg was being declared outside the scope it was referenced in:
Hey Tom, Yes got it working, i had a miss of everything everywhere by trying to get it working.
Thanks for your Help.
is working on a reply...