Copied to clipboard

Flag this post as spam?

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


  • Rich Kneece 1 post 21 karma points
    Feb 29, 2012 @ 01:23
    Rich Kneece
    0

    Using Library.MediaById in v5

    Hi All,

    We're experimenting building a small site with v5, and while it has some benefits figuring out how to "do stuff you did before" is a challenge.

    One such challenge is we're trying to randomly display an image picked among all images in a particular media folder. Previously we were able to do this with something like...

                      <umbraco:Macro runat="server" language="cshtml">
                        
                      @inherits umbraco.MacroEngines.DynamicNodeContext

                          <span>
                            @{
                              // ### random image from 740x310 pics folder ###                      
                                dynamic folder = Library.MediaById( *** the numeric ID of the media folder here *** );
                                var image = folder.Children.Where("nodeTypeAlias = \"Image\"").Random();
                            }
                            <img src="@image.UmbracoFile" alt="@image.Name" />
                          </span>

                      </umbraco:Macro>

    But for the life of me, we can't figure out how to do this in v5. Any thoughts/ideas/suggestions?

Please Sign in or register to post replies

Write your reply to:

Draft