I'm attempting to set up some pages that need a random image displayed. I've copied the code in this post exactly as it appears in the last code posted.
I need to do exactly the same thing, but I can't seem to get this to
work in my environment. The issue is that I'm not sure how to interpret the XSL, so I don't know how the variable "mediaFolderID" is getting populated in the
pages.
Is that value coming from a property named "randomImage" of the page template, and can it be a folder so it selects one of the children?
Sorry for the newb question, just getting started here.. :)
Here's what I have in my template:
<umbraco:Macro Alias="RandomBgImg" randomImage="1216" runat="server"></umbraco:Macro>
Yes, based on the last code snippet for you referenced post, you would need a property on your document type with an alias of randomImage of data type media picker. By the looks of the code, it is expecting you to choose a folder.
In terms of your macro code in your template, you shouldn't need the randomImage attribute as this is retreived from the document type.
This generates a random background from an media folder. Based on the Folder Node ID *for this script to work the images must be upload as images, not as a file.
The solution posted works except that I only have three images to randomly select. The randomization returns no image fairly often, so it's not quite reliable.
Since upgrading the site to 4.5.2, the randomization isn't working correctly anymore, there frequency of no image coming back is now a significant problem:
</xsl:when> <xsl:otherwise> <xsl:comment> Folder Id was not provided. </xsl:comment> <xsl:call-template name="drawFromDefault" /> </xsl:otherwise> </xsl:choose> </xsl:template>
Trouble with XSLT / parameters
I'm attempting to set up some pages that need a random image displayed. I've copied the code in this post exactly as it appears in the last code posted.
I need to do exactly the same thing, but I can't seem to get this to work in my environment. The issue is that I'm not sure how to interpret the XSL, so I don't know how the variable "mediaFolderID" is getting populated in the pages.
Is that value coming from a property named "randomImage" of the page template, and can it be a folder so it selects one of the children?
Sorry for the newb question, just getting started here.. :)
Here's what I have in my template: <umbraco:Macro Alias="RandomBgImg" randomImage="1216" runat="server"></umbraco:Macro>
Hey Dave,
Yes, based on the last code snippet for you referenced post, you would need a property on your document type with an alias of randomImage of data type media picker. By the looks of the code, it is expecting you to choose a folder.
In terms of your macro code in your template, you shouldn't need the randomImage attribute as this is retreived from the document type.
Matt
Are you using Umbraco 4.5?, the snippet on the other page isnt gonna work since the xml schema has changed.
Yes, I am using 4.5. Is there any examples or other posts that I should refer to?
I don't know. I can help you with an exemple tho.
This generates a random background from an media folder. Based on the Folder Node ID
*for this script to work the images must be upload as images, not as a file.
<xsl:variable name="folderNodeID" select="1072"/>
<xsl:variable name="randomImageNumber" select="round( Exslt.ExsltMath:random() * (count(umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image) -2 ) + 1 )"/>
<div id="yourID" style="background-image:url({umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image[$randomImageNumber]/umbracoFile});"></div>
Niels,
Thanks for the reply,
The solution posted works except that I only have three images to randomly select. The randomization returns no image fairly often, so it's not quite reliable.
Any thoughts?
Hey dave,
i have failed :P (i'm still a noob at xslt). I have changed the second line and works correct now.
here is the new code:
<xsl:variable name="folderNodeID" select="1072"/>
<xsl:variable name="randomImageNumber" select="ceiling( Exslt.ExsltMath:random() * (count(umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image) ) )"/>
<div id="yourID" style="background-image:url({umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image[$randomImageNumber]/umbracoFile});"><div>
Hope this works for you
Bump
Since upgrading the site to 4.5.2, the randomization isn't working correctly anymore, there frequency of no image coming back is now a significant problem:
Here is the current XSLT:
Can anyone see what the issue is here?
is working on a reply...