This is not too intuitive for me, so i hope some of you are able to help.
I've made a media folder containing 9 images. I need to fecth 3 of those images for my master template on each page refresh.
In the forums i found a nice xslt to pick any number of random images from a mediafolder. My only problem is that i dont know how to connect that xslt to the specific folder. I've tried to hardcode the ID, but that wont work for me.
<msxsl:script language="c#" implements-prefix="randomTools"> <msxsl:assembly href="../bin/umbraco.dll"/> <![CDATA[ /// <summary> /// Gets a random integer that falls between the specified limits /// </summary> /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param> /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param> /// <returns>A random integer within the specified range</returns> public static int GetRandom(int lowerLimit,int upperLimit) { Random r = umbraco.library.GetRandom(); int returnedNumber = 0; lock (r) { returnedNumber = r.Next(lowerLimit, upperLimit); } return returnedNumber; } ]]> </msxsl:script> </xsl:stylesheet>
I should note that i'm very grateful that you're trying to help me. I hope you can tolerate my stupid questions, but this specific task is hard for me to grasp :)
anyway: I made a property for my textpage under "content" called RandomImages as alias and picked the folder as you suggested above. When i try to write the macro in my master or the textpage master i just get blank content. In my page source there's nothing but the div container?
I had a similar problem where I had renamed the property after adding pages e.g. if you had originally named the property 'RandomImage', created a new page, and then renamed the property 'propertyImage' i.e. changed the case of the first letter.
The cached name for the property was still called 'RandomImage' for those pages I had already created and my XSLT couldn't find the property (case sensitive).
To fix I had to republish the entire site to fix it.
Right click on the Content node and select 'Republish entire site' from the menu.
That made no difference. The pages where i selected the "Banners" folder are still not outputting anything and the page where i selected my "test" folder is still giving me: Error parsing XSLT file: \xslt\RandomImage.xslt
I've tried a couple of other xslt files around the forum and through nibble and i get errors on all of them more or less :/
Thank you very much for your effort. Unfortunately i still get the same error msg or nothing at all.
I just tried the change the casing of the alias and now i get the parsing error on the pages that use "Banners" folder, but not the pages that uses the "test" folder. Very peculiar indeed.
Is there some way i can test where the chain falls off?
That's my media folder, and i dont have the "Banners" nor the "Test" folder that i have in Umbraco backoffice, instead if have a folder for every single image, in which there also lies a thumbnail of each image.
<msxsl:script language="c#" implements-prefix="randomTools"> <msxsl:assembly href="../bin/umbraco.dll"/> <![CDATA[ /// <summary> /// Gets a random integer that falls between the specified limits /// </summary> /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param> /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param> /// <returns>A random integer within the specified range</returns> public static int GetRandom(int lowerLimit,int upperLimit) { Random r = umbraco.library.GetRandom(); int returnedNumber = 0; lock (r) { returnedNumber = r.Next(lowerLimit, upperLimit); } return returnedNumber; } ]]> </msxsl:script> </xsl:stylesheet>
Again, in my media section i have two folders: "Banners" and "test". If i pick the "Test" folder on some of my pages i get no output, but if i choose the "Banners" folder i get a parsing error (displayed earlier in this post).
I'm really interested in what that parsing error consists of. I've even checked the casing of all my aliases regarding this randomImage xslt and i can't find any valid reason as to why it keeps failing or outputting nothing. But as i said, i dont see my two folders if i access the media folder through explorer/stifinder.
probably a contentPicker. It's used for a <a> tag as a link - but you could start by commenting out the <a> ... </a> part in your xslt and see if you can get the rest working.
That didn't help, not even if i remove the whole <a> section.
I just tried this xslt, wich i think the randomImage xslt is build from, and there i have no problem getting the <li>'s if a page has subpages. Is there any way to rewrite this to spit out a random number of images from a folder instead?
<msxsl:script language="c#" implements-prefix="randomTools"> <msxsl:assembly href="../bin/umbraco.dll"/> <![CDATA[ /// <summary> /// Gets a random integer that falls between the specified limits /// </summary> /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param> /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param> /// <returns>A random integer within the specified range</returns> public static int GetRandom(int lowerLimit,int upperLimit) { Random r = umbraco.library.GetRandom(); int returnedNumber = 0; lock (r) { returnedNumber = r.Next(lowerLimit, upperLimit); } return returnedNumber; } ]]> </msxsl:script> </xsl:stylesheet>
<msxsl:script language="c#" implements-prefix="randomTools"> <msxsl:assembly href="../bin/umbraco.dll"/> <![CDATA[ /// <summary> /// Gets a random integer that falls between the specified limits /// </summary> /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param> /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param> /// <returns>A random integer within the specified range</returns> public static int GetRandom(int lowerLimit,int upperLimit) { Random r = umbraco.library.GetRandom(); int returnedNumber = 0; lock (r) { returnedNumber = r.Next(lowerLimit, upperLimit); } return returnedNumber; } ]]> </msxsl:script> </xsl:stylesheet>
Thank you for your reply. I have one silly question before trying this. How and where do i specify the medicaCurrent type? That might as well have been the problem all along?
When creating the macro, in the right panel you see two tabs called "Macro Properties" and "Parameters". Select "Parameters" and enter a new parameter called MediaFolder as alias and name, check "Show" and select mediaCurrent in the dropdown - then click "Add" and save the macro.
Then afterwards add the macro to your template using the "Add macro" button - then you will be prompted to locate a media folder.
Pick 3 random images from a Media folder
Hi there
This is not too intuitive for me, so i hope some of you are able to help.
I've made a media folder containing 9 images. I need to fecth 3 of those images for my master template on each page refresh.
In the forums i found a nice xslt to pick any number of random images from a mediafolder. My only problem is that i dont know how to connect that xslt to the specific folder. I've tried to hardcode the ID, but that wont work for me.
The xslt i found looks like this:
Am i supposed to pass in the ID through this snippet:
<umbraco:Macro Alias="RandomImage" runat="server"></umbraco:Macro>
If yes, how?
Hi Martin, in your source above you need a doctype property called "randomImage" of type media picker selecting the media folder.
You could change that to a macro property as you suggest yourself if you want instead.
>Tommy
Hi Tommy
Thanks for your reply :)
Being the Umbraco newb that i am, i'm not quite sure i get your point. Could you be more specific?
Thanks in advance!
The only thing i did was to make a "Banners" image folder in the media section and then made the xslt with a macro.
where do i go from there? Should i make a content type or something similar?
To make the macro work as it is you need to:
1. Change your document type of the node (or make a new document type) to include a property called "randomImage" of type media picker
2. In your content node, using the doctype of 1), select the media folder in the "randomImage" property
>Tommy
Hi again Tommy
I should note that i'm very grateful that you're trying to help me. I hope you can tolerate my stupid questions, but this specific task is hard for me to grasp :)
anyway: I made a property for my textpage under "content" called RandomImages as alias and picked the folder as you suggested above. When i try to write the macro in my master or the textpage master i just get blank content. In my page source there's nothing but the div container?
oh, and im using this macro call:
<umbraco:Macro Alias="RandomImage" runat="server"></umbraco:Macro>
sure, no problem.
Please validate that your macro and property names are correctly named and cased.
Ok, so:
· My Property is called "Random Image" and has an alias of "randomImage" - type Media Picker
· On my master template i use the following macro: <umbraco:Macro Alias="randomImage" runat="server"></umbraco:Macro>
It seems like this variable isn't recieving data for some peculiar reason:
<xsl:variable name="mediaFolderID" select="number($currentPage/data [@alias = 'randomImage'])" />
I just tried making a new folder called "test" which contains 6 images and now i get this:
Error parsing XSLT file: \xslt\RandomImage.xslt
When i use the folder "Banners" with 9 images, it doesn't output anything :/ ?
Not sure if this will help but...
I had a similar problem where I had renamed the property after adding pages e.g. if you had originally named the property 'RandomImage', created a new page, and then renamed the property 'propertyImage' i.e. changed the case of the first letter.
The cached name for the property was still called 'RandomImage' for those pages I had already created and my XSLT couldn't find the property (case sensitive).
To fix I had to republish the entire site to fix it.
Right click on the Content node and select 'Republish entire site' from the menu.
Kevin
Sorry Kevin
That made no difference. The pages where i selected the "Banners" folder are still not outputting anything and the page where i selected my "test" folder is still giving me: Error parsing XSLT file: \xslt\RandomImage.xslt
I've tried a couple of other xslt files around the forum and through nibble and i get errors on all of them more or less :/
You could try the following:
In your template use the following code:
<umbraco:Macro MediaFolder="[#randomImage]" Alias="randomImage" runat="server"></umbraco:Macro>
Note: using #randomImage (hash sign in front of the property name) will use the value of the property
In your XSLT replace the following:
<xsl:variable name="mediaFolderID" select="number($currentPage/data [@alias = 'randomImage'])" />
with
<xsl:variable name="mediaFolderID" select="/macro/MediaFolder" />
then you need to add a parameter to the 'Parameters' tab in the Macro definition for randomImage:
Alias: MediaFolder
Name : Media folder
Type : number
and make sure you check the 'Show' checkbox
Kevin
Hi Kevin
Thank you very much for your effort. Unfortunately i still get the same error msg or nothing at all.
I just tried the change the casing of the alias and now i get the parsing error on the pages that use "Banners" folder, but not the pages that uses the "test" folder. Very peculiar indeed.
Is there some way i can test where the chain falls off?
Ok, this might have somthing to do with my problem?
http://img412.imageshack.us/i/foldersm.jpg/
That's my media folder, and i dont have the "Banners" nor the "Test" folder that i have in Umbraco backoffice, instead if have a folder for every single image, in which there also lies a thumbnail of each image.
Or is it supposed to do it like that? :/
Hi Martin - what-s your current setup - and how does your randomImage xslt look like?
Hi Tommy
I'm using the vistaDB solution on a local host install of the newest Umbraco system (4.0.3 i think?)
My macro call from my master template now looks like this (after taking Kevins advice):
And my xslt now look like this, also in regard to Kevins advice:
Again, in my media section i have two folders: "Banners" and "test". If i pick the "Test" folder on some of my pages i get no output, but if i choose the "Banners" folder i get a parsing error (displayed earlier in this post).
I'm really interested in what that parsing error consists of. I've even checked the casing of all my aliases regarding this randomImage xslt and i can't find any valid reason as to why it keeps failing or outputting nothing. But as i said, i dont see my two folders if i access the media folder through explorer/stifinder.
Hi Martin,
there appears to be a problem with this line:
Apparently the
./data[@alias = 'internalUrl']
part does not produce a valid node id
>Tommy
Hi Tommy
Ok, that could be a step in the right direction, I just don't know what to do with that knowledge?
What could i try instead?
You have to make sure that the property of your doctype called "internalUrl" is actually a node id. What does your internalUrl property contain?
Well it doesn't exist, i actually just copied the main setup of this xslt file from someone else in here.
But maybe i should make it instead of deleting it as i can see that i can a link on each img, but what sort of doctype would that be?
can have a link was what i meant
probably a contentPicker. It's used for a <a> tag as a link - but you could start by commenting out the <a> ... </a> part in your xslt and see if you can get the rest working.
Will do!
Thanks for your help thus far, i apreciate it a lot!
Hi again.
That didn't help, not even if i remove the whole <a> section.
I just tried this xslt, wich i think the randomImage xslt is build from, and there i have no problem getting the <li>'s if a page has subpages. Is there any way to rewrite this to spit out a random number of images from a folder instead?
what do you get out now - a fixed amount of random images? And you want a random number of images?
right now it outputs <li> tags containing my subpages, if the current page has subpages.
So the whole pick a folder and show images from it is missing, and yes i would very much like a random number of images.
a random number of fixed order images, or a fixed number of random order images ?
above question was: what are you looking for...
The two options require quite different solutions
Hi Martin, now I read your original post, and I see you want e.g. 3 random images shown.
This works for me as a macro with parameter MediaFolder (alias MediaFolder) type mediaCurrent. When inserting the macro you select the media folder:
Hi Tommy
Thank you for your reply. I have one silly question before trying this. How and where do i specify the medicaCurrent type? That might as well have been the problem all along?
Thanks in advance
Nevermind, i found it ^^
i'll try it right away
When creating the macro, in the right panel you see two tabs called "Macro Properties" and "Parameters". Select "Parameters" and enter a new parameter called MediaFolder as alias and name, check "Show" and select mediaCurrent in the dropdown - then click "Add" and save the macro.
Then afterwards add the macro to your template using the "Add macro" button - then you will be prompted to locate a media folder.
Oh for the love of god, you're a bloody world champion.
THAT WAS IT!!! A god damned little forgotten type.
Seriously, you're a star. Thank you so much!
You're welcome - I'm glad that we worked it out.
>Tommy
I like the way you put that. Like i did anything ^^
Something like this:
is working on a reply...