Copied to clipboard

Flag this post as spam?

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


  • patrick 41 posts 93 karma points
    Feb 01, 2012 @ 20:20
    patrick
    0

    Combining image and folder selection with DAMP (with razor)

    Is it possible to use a DAMP media picker to select multiple folders, and also multiple images?

    Right now i'm using the following code to display selected images, but as soon as I also select a folder this code will fail.

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
         @foreach (var item in Model.images.mediaItem)
         {   
            var image = item.Image;
                        
            <a href="@image.umbracoFile">
               <img alt="@image.nodeName" src="@image.umbracoFile">
            </a>
         }
    </umbraco:Macro>

    Logical as a folder likely won't have an Image property.

    Is there a method that I can use to display the XML structure for an DAMP item?

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Feb 01, 2012 @ 20:34
    Jeroen Breuer
    0

    Hello,

    The DAMP xml is stored in the umbraco.config file (/App_Data/umbraco.config). There you can see your xml and you can chance your Razor code to support both multiple folders and images. This is possible :).

    Jeroen

  • patrick 41 posts 93 karma points
    Feb 01, 2012 @ 21:18
    patrick
    0

    Hi Jeroen,

    Thanks for the quick response, I will look into this right away.

    Patrick

  • patrick 41 posts 93 karma points
    Feb 02, 2012 @ 13:24
    patrick
    0

    Hi Jeroen,

    For now I came up with something like this:

     <umbraco:Macro  runat="server" language="cshtml">
                      @inherits umbraco.MacroEngines.DynamicNodeContext
                      @using umbraco.MacroEngines;
                      @{  
                          foreach (var item in Model.images.mediaItem)
                          {
                            var images = item.XPath("Image");
                            if(images != null)
                            {
                                foreach (var image in images)
                                {
                                   <a href="@image.umbracoFile">
                                      <img alt="@image.nodeName" src="@image.umbracoFile">
                                   </a>
                                }
                            }
                            var folders = item.XPath("Folder");
                            if(folders != null)
                            {
                                foreach (var folder in folders)
                                {
                                  var media = Model.MediaById(folder.id);
                                  var folderImages = media.Children;
                                  foreach(var folderImage in folderImages)
                                  {
                                      <a href="@folderImage.umbracoFile">
                                          <img alt="@folderImage.nodeName" src="@folderImage.umbracoFile">
                                      </a>
                                  }
                                }
                             }
                          }
                      }
                      </umbraco:Macro>
  • 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