Copied to clipboard

Flag this post as spam?

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


  • John Halsey 59 posts 220 karma points
    Apr 25, 2014 @ 13:45
    John Halsey
    0

    List Images from DAMP media picker using Razor

    Hello,

    I have added a Digibiz Advanced Media Picker to a doc type and added 2 images to the page. I can't quite work out how to list the images with Razor, any advice welcome. Here is some of the XML.

    <images>
            <DAMP fullMedia="">
              <mediaItem>
                <Image id="1433" version="11e5347c-1982-40e7-a0ca-0cb46b55b978" parentID="1431" level="3" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2014-04-25T10:03:13" updateDate="2014-04-25T10:03:38" nodeName="Chrysanthemum" urlName="chrysanthemum" writerName="Admin" nodeTypeAlias="Image" path="-1,1049,1431,1433">
                  <umbracoFile>/media/10281/Chrysanthemum.jpg</umbracoFile>
                  <umbracoWidth>650</umbracoWidth>
                  <umbracoHeight>488</umbracoHeight>
                  <umbracoBytes>418999</umbracoBytes>
                  <umbracoExtension>jpg</umbracoExtension>
                  <altText>Flower</altText>
                </Image>
              </mediaItem>
              <mediaItem>
                <Image id="1434" version="f1a4f7f7-edf0-4a04-8301-686b79952053" parentID="1431" level="3" writerID="0" nodeType="1032" template="0" sortOrder="2" createDate="2014-04-25T10:03:14" updateDate="2014-04-25T10:03:47" nodeName="Desert" urlName="desert" writerName="Admin" nodeTypeAlias="Image" path="-1,1049,1431,1434">
                  <umbracoFile>/media/10282/Desert.jpg</umbracoFile>
                  <umbracoWidth>620</umbracoWidth>
                  <umbracoHeight>345</umbracoHeight>
                  <umbracoBytes>244243</umbracoBytes>
                  <umbracoExtension>jpg</umbracoExtension>
                  <altText>Desert</altText>
                </Image>
              </mediaItem>
            </DAMP>
          </images>
    

    I have written this Razor do far. But I also want to check if there are any images selected at all, as I don't want to output the div with id="rightCol" if there are no images.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
        @{
    
                <div class="col" id="rightCol">
                    @foreach(var image in Model.images.Children)
                    {
                        var file = image.Image;
                        <img src="@file.umbracoFile" alt="@file.altText" class="dampImage" />
                    }
                </div>
    
        }
    

    Many Thanks.

  • John Halsey 59 posts 220 karma points
    Apr 25, 2014 @ 13:54
    John Halsey
    0

    I worked it out. removed .Children from the foreach loop.

Please Sign in or register to post replies

Write your reply to:

Draft