Here is my XSLT.... Basically, what I am trying to do is Use the mediaFolderId if it is present for the current page. If not, I want it to use the one from a parent page.
<xsl:param name="currentPage"/>
<xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
<xsl:variable name="mediaFolder" select="$currentPage/ancestor-or-self::*[normalize-space(mediaFolderId)][1]/mediaFolderId" />
<xsl:template match="/">
<!-- Displays all images from a folder in the Media Library -->
<xsl:choose>
<xsl:when test="number($mediaFolder)">
<xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
<xsl:if test="umbracoFile !=''">
<img src="/{umbraco.library:UrlEncode(umbracoFile)}" class="bgM" />
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="umbraco.library:GetMedia($mediaFolder, true())/Image">
<xsl:if test="umbracoFile !=''">
<img src="/{umbraco.library:UrlEncode(umbracoFile)}" class="bgM" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
What am I doing wrong (probably simple solution)
In my XSLT I want to create two variables. One for the Media Folder Id for the current page:
And one for the Media Folder ID for the parent page. (So if there isn't a media folder ID present, it will pull the id from the parent.
For some reason, the parent one is not working.
Hi Ryan,
TIf you know the nodeTypeAlias (e.g. 'Textpage') of your document type, you should use that:
Otherwise, use the more generic:
/Dennis
Hi Ryan,
Sounds like you want what's referred to as the recursive value of that property (i.e., taken from the first ancestor where it's specified)?
You can do that in one select:
/Chriztian
@Chriztian
When trying your code, I get this error:
System.Xml.Xsl.XslLoadException: Prefix 'ancestor-or-self' is not defined.
@Dennis, this is the error I get with your code.
System.OverflowException: Value was either too large or too small for an Int32.
Here is my XSLT.... Basically, what I am trying to do is Use the mediaFolderId if it is present for the current page. If not, I want it to use the one from a parent page.
Yeah, sorry 'bout that - writing this on my phone, so had to fix a couple times :)
Should be good now.
The code above is not working. I pasted your code in, but it still doesn't work. Do I have something set up wrong?
Got it working, I didn't change part of the code below in the Choose. Once I updated that to just mediaFolder it started working. Thanks @Chriztian
Just for completion. Here is the working code. Including a default media folder of "4096" if there is nothing selected in the Parent.
is working on a reply...