Copied to clipboard

Flag this post as spam?

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


  • Rocoeh 65 posts 86 karma points
    Aug 07, 2012 @ 17:36
    Rocoeh
    0

    Output my gallery in razor

    I have a folder called "gallery" you can create a galleryCategory which is the title of the gallery. In the gallery category you can add multiple galleryItems(these are just pics_. I need a loop inside a loop in Razor to output my html which is

     

    <div class="gallery-category">               
                   
                    <h3>edinburgh’s great icon</h3>
                   
                    </div>   
                   
                    <div class="slides">
                        <div class="gallery-slider" style="width: 1740px; margin-left: 0px;">
                            <img width="120" height="120" data-fullsize="img/galleryimages/fullsize/1.jpg" alt="1" src="img/galleryimages/1.jpg" class="gallery-image">
                         
              
                   
    </div>  

     

    my razor

     

    <asp:content ContentPlaceHolderId="mainContent" runat="server">
      <umbraco:Macro runat="server" language="cshtml">

    @foreach (var gallery in Model.NodeById(1599).Children) {
        
        <h2>gallery.Title</h2>
        
        @foreach (var galleryitem in NodeById(gallery.id).Children) {
        
        //output the pics here
        
        }
    }
    </umbraco:Macro>

     

     

     

  • Funka! 398 posts 661 karma points
    Aug 07, 2012 @ 20:14
    Funka!
    0

    What are the properties on your "galleryitem" node? (This is a document type, and not a media type, correct?)

    As an example, if you are using the "upload" datatype directly on a document type called "pic", here is one way to do it...

    @foreach (var galleryitem in NodeById(gallery.id).Children) {
        //output the pics here
        <img src="@galleryitem.pic" alt="" />
    }

    If you were using a "media picker" datatype called imageId, here is another way to do that... (since a media picker just stores an ID for reference, not the name of the file like the previous example.)

    @foreach (var galleryitem in NodeById(gallery.id).Children) {
        //output the pics here
        var m = Library.MediaById(galleryitem.imageId);
        <img src="@m.umbracoFile" alt="" />
    }

    Best of luck to you!

  • Rocoeh 65 posts 86 karma points
    Aug 08, 2012 @ 10:37
    Rocoeh
    0

    got it, what you posted was close,

    NodeById(gallery.id).Children

    This was giving me an error

    @foreach (var gallery in Model.NodeById(1599).Children) {
        
        <h2>@gallery.Id</h2>
        
         foreach (var galleryitem in gallery.Children) {
       

        <img src="@galleryitem.pic" alt=""/>


          
    }
       
       
    }

  • Funka! 398 posts 661 karma points
    Aug 09, 2012 @ 01:15
    Funka!
    0

    Hello again Rocoeh,

    You did not mention what kind of properties were on your "galleryitem" content type. Without knowing this, it is hard to guess exactly what the problem might be. (Different data types have different ways of storing the underlying data.)

    Good luck!

Please Sign in or register to post replies

Write your reply to:

Draft