Hi, I'm having an issue with some XSLT that I'm hoping someone can help me with.
I have Gold Sponsors, and Silver Sponsors, each under their respective parent nodes, and I'm looking to randomly choose one of the them from the entire list.
So:-
- Gold Sponsors
----Sponsor 1
----Sponsor 2
- Silver Sponsors
----Sponsor 3
----Sponsor 4
----Sponsor 5
Now my code to figure out an index (from the overall number of sponsors) looks like this:-
What I want to do now is select a specific node, either from the gold or the silver sponsors, depending on the value of the randomNodeIndex. I was hoping to set a variable to be my random node, and work with that by passing it into my template, but I've had no luck.
Which version of Umbraco are you working with? If it's 4.6 or 4.7 I'd recommed you to check out the Razor syntax where you're able to write your own extension class for choosing a single, random and unique DynamicNode.
Check it out here under "Custom extenstion methods"
Haha.... thanks for your help guys. Jesper, I think the xslt in that thread makes sense. I can make my variable be the id of the node, and not the node itself. Then get the node later, either in the template, or when passing it to the template.
Bo, I need a quick solution, so I might go with the XSLT for now coz that's what I'm most comfortable with.... But I promise you I'll have a look at Razor when I get a chance. :-)
Set Variable to a document node
Hi, I'm having an issue with some XSLT that I'm hoping someone can help me with.
I have Gold Sponsors, and Silver Sponsors, each under their respective parent nodes, and I'm looking to randomly choose one of the them from the entire list.
So:-
- Gold Sponsors
----Sponsor 1
----Sponsor 2
- Silver Sponsors
----Sponsor 3
----Sponsor 4
----Sponsor 5
Now my code to figure out an index (from the overall number of sponsors) looks like this:-
What I want to do now is select a specific node, either from the gold or the silver sponsors, depending on the value of the randomNodeIndex. I was hoping to set a variable to be my random node, and work with that by passing it into my template, but I've had no luck.
Is there a way to set my variable to be my random sponsor, or do I have to call my template directly within the choose statement?
Cheers,
Sean
Sorry about the code.... You know how difficult it is to simply post code on this forum?!?!?!
Hi Sean,
Which version of Umbraco are you working with? If it's 4.6 or 4.7 I'd recommed you to check out the Razor syntax where you're able to write your own extension class for choosing a single, random and unique DynamicNode.
Check it out here under "Custom extenstion methods"
http://umbraco.com/follow-us/blog-archive/2011/2/28/umbraco-razor-feature-walkthrough-%E2%80%93-part-3
Hi Sean,
Or you could look in this thread to see two other approaches.
Regards
Jesper Hauge
Ssh, Jesper - was trying to hijack members to the Razor Empire here ;)
j/k - nice thread there!
Haha.... thanks for your help guys. Jesper, I think the xslt in that thread makes sense. I can make my variable be the id of the node, and not the node itself. Then get the node later, either in the template, or when passing it to the template.
Bo, I need a quick solution, so I might go with the XSLT for now coz that's what I'm most comfortable with.... But I promise you I'll have a look at Razor when I get a chance. :-)
is working on a reply...