Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andreas Älveborn 31 posts 52 karma points
    Sep 29, 2010 @ 02:19
    Andreas Älveborn
    0

    Display random node in medium trust

    Hi all..

    I have been going crazy to find out a way to display a random node (banner item). I have done alot of tips and tricks from the forum but the working ones wont work in medium trust.

    I have also tried to create a xslt extension to get a random number, but the <xsl:sort> wont work when doing so anyway.

    Have someone found a way to display a random item in medium trust?

  • Martin Rud 232 posts 902 karma points c-trib
    Sep 29, 2010 @ 04:29
    Martin Rud
    0

    Hi Dekline,

    Haven´t tested it, but maybe this will work for you: http://blogs.thesitedoctor.co.uk/tim/CommentView,guid,1f190396-eaf7-49a2-a3f0-3873df4a0ccd.aspx

    Regards, Martin

  • Andreas Älveborn 31 posts 52 karma points
    Sep 29, 2010 @ 13:51
    Andreas Älveborn
    0

    Hi Martin

    The thing is that i'm not allowed to run

    <msxml:script  language="JavaScript" implements-prefix="math"></msxml:script>

    in medium trust. But could I create some sort of xslt extension that i will be able to <xsl:sort> with?

  • Martin Rud 232 posts 902 karma points c-trib
    Sep 29, 2010 @ 14:09
    Martin Rud
    0

    Hi,

    Ok, now I see. I have no other solution, sorry...

  • Anders Brännmark 226 posts 277 karma points
    Sep 29, 2010 @ 21:06
    Anders Brännmark
    0

    Do you only need one random item? Or a whole list of random items?

    If only one you could do it in a couple of ways with an xslt extension. One is to generate a random number with max number equal to the total count, then you can use an if statement to check position() = your random number, if true render the item. Another way to do it is send in all ids of the banner nodes to the xslt extension, make a random function to return the id of the random node, and then use xslt to return it.

    If you need a list of random items you propberly need to look into an xslt extension returning a nodeset using nodefactory.

  • Andreas Älveborn 31 posts 52 karma points
    Sep 29, 2010 @ 21:31
    Andreas Älveborn
    0

    Hi there Anders

    This is a banner system and I would like the administrator to choose how many banners to display, and IF they will be in a random order or not. So I guess your third suggestion by using nodefactory would do it.

    Would it on the other hand be better to create a usercontrol for this? Or is an xslt extension the best way? I'm thinking it maybe is a good idea to cache the macro for a faster experience ? 

  • Anders Brännmark 226 posts 277 karma points
    Sep 29, 2010 @ 21:51
    Anders Brännmark
    0

    xslt extensions are very very powerfull. You could perhaps make it a bit generic so you can use it for other random functions also. You might want to consider to use the nodeset of all "your" banner items as an in parameter, and then use .net to random the nodeset and return it back. Hopefully you understand what I mean.

  • Andreas Älveborn 31 posts 52 karma points
    Sep 29, 2010 @ 21:57
    Andreas Älveborn
    0

    Yeah, I understand what you mean. Never used extensions with nodesets before, but I know there's a how-to video about this on umbraco.org. I'll check that out.. Thank you for your help :)

Please Sign in or register to post replies

Write your reply to:

Draft