Copied to clipboard

Flag this post as spam?

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


  • Rasmus Fjord 659 posts 1546 karma points c-trib
    Oct 31, 2011 @ 15:44
    Rasmus Fjord
    0

    simple gallery using standard media picker razor

    Hey there

    Im new to the umbraco platform :)

    What im tryin to do is just using the standard media picker on a page where instead of selecting a single image(tried that and it working quickly).

    So in the media picker im just picking a media folder instead, and I just want to print out the images through Razor.

    @{
        var mediaItems = Model.Media.galleryItem;

        foreach (var item in mediaItems)
        {

            <img src="@item.UmbracoFile" />
        }
    }

    "galleryItem" is the alias for the media picker.

    Anyone got a quick comment for it :)

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Oct 31, 2011 @ 16:00
    Tim Geyssens
    0

    Here is a quick example, it will output a single image if a single image is choses or all images if a folder is chosen

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{ var numberOfItems = 10; }
    <ul>
        @foreach (var item in @Model.Children.Where("Visible").OrderBy("UpdateDate").Take(numberOfItems))
        {
            <li>@item.Name
            if(item.HasValue("fileFromMedia")){
            var chosenMedia = Model.MediaById(item.fileFromMedia);
            
            @if(chosenMedia.NodeTypeAlias == "Image")
            {
              <p>Single Image</p>
               <img src="@item.Media("fileFromMedia","umbracoFile")" width="200" />
            }
            else if(chosenMedia.NodeTypeAlias == "Folder")
            {
              <p>Image gallery</p>
              foreach(var img in chosenMedia.Children)
              {
                <img src="@img.umbracoFile" width="200" />
              }
            }
            
      }else{
        <p>No image</p>
      }
      </li>       
        }
    </ul>
  • Rasmus Fjord 659 posts 1546 karma points c-trib
    Oct 31, 2011 @ 16:02
    Rasmus Fjord
    0

     Thumbs up Tim :)

     

    First time im getting to use it after the course :)

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Oct 31, 2011 @ 16:10
    Jeroen Breuer
    0

    Hi Rasmus,

    Instead of selecting a folder you could also use the Digibiz Advanced Media Picker. There you can select multiple images. Here is a quick demo: http://www.screenr.com/gz0s.

    Jeroen

  • Rasmus Fjord 659 posts 1546 karma points c-trib
    Oct 31, 2011 @ 16:32
    Rasmus Fjord
    0

    Thx Jeroen :) 

    Always nice to know their are other choices aswell :) For this small project this should be enough

  • Amir Khan 1199 posts 2567 karma points
    Feb 06, 2012 @ 21:05
    Amir Khan
    0

    So for some reason when I try the above i get "The name 'ChosenMedia' does not exist in the current context"..Any idea why?

     

    Thanks!

    Amir

  • Rasmus Fjord 659 posts 1546 karma points c-trib
    Feb 15, 2012 @ 13:15
    Rasmus Fjord
    0

    Ey Amir


    Sorry for not gettin back to ya, dunno if you have gotten it to work but try this, its a simpler version, if not pls post your razor to me :)

    @{ 
         var  chosenMedia  =  Model.MediaById(@Parameter.nodeSelector);

         if  (chosenMedia.NodeTypeAlias  ==  "Folder")
         {
             foreach  (var  img  in  chosenMedia.Children)
             {
                 if  (img.NodeTypeAlias  ==  "Image")
                 {
                             
                     <img  src="@img.umbracoFile"/>
                
                 }
             }
         } 
    }

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies