Copied to clipboard

Flag this post as spam?

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


  • Keith R Hubbard 175 posts 403 karma points
    Oct 13, 2014 @ 13:35
    Keith R Hubbard
    0

    List children of a content ID with MVC

    I want to list all child images and link of GalleyCatagorie on the homepage. before with dynamic node i would have used NodebyID. The example below is from dynamic node, I want to know how to do this with MVC.

        @{
    
        <div class="FeaturedProduct">
        @foreach (var group in @Model.NodeById(2045).Children.InGroupsOf(3))
        {
           foreach(var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");
    
                // If there is not photo, fallback to the placeholder
                var src = @item.Cropper ?? "/images/Placeholders/photo_placeholder.gif";
                <div class="image">
                 @if (Model.HasValue("Cropper"))
    {
        <img src="@Model.Cropper.Find("@name", "250").url" /><br />
    
    }
                </div>            
            }
    
            // Clear after each group of 3
            <div class="clearBoth"> </div>
        }
        </div>
    }
    
  • Dan Lister 416 posts 1974 karma points c-trib
    Oct 13, 2014 @ 13:53
    Dan Lister
    0

    Hi Keith,

    I think something like the following should work...

    @foreach (var group in Umbraco.TypedContent(2045).Children.InGroupsOf(3))
    {
    }
    

    Thanks, Dan.

  • Keith R Hubbard 175 posts 403 karma points
    Oct 13, 2014 @ 14:20
    Keith R Hubbard
    0

    Here is the updated code but i do not get images or links it shows the divs

    @{

    <div class="FeaturedProduct">
        @foreach (var group in Umbraco.TypedContent(1101).Children.InGroupsOf(3))
        {
            foreach (var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");
    
                // If there is not photo, fallback to the placeholder
                var src = @item.GetCropUrl("cropper", "thumbnail");
                <div class="image">
                    @if (Model.Content.HasValue("cropper"))
                    {
                        <img src="@item.Url" alt="@item.Name" /><br />
                        <h3><a href="@item.Url">@item.Name</a></h3>
                    }
                </div>
            }
    
            // Clear after each group of 3
            <div class="clearBoth"> </div>
        }
    </div>
    

    }

  • Dan Lister 416 posts 1974 karma points c-trib
    Oct 13, 2014 @ 14:38
    Dan Lister
    0

    Hi Keith,

    I think your if statement is using the wrong object and your image is using the wrong url. Instead of Model, shouldn't it use item?

    if (item.HasValue("cropper"))
    {
        <div class="image">
            <img src='@item.GetCropUrl("cropper", "thumbnail")' alt="@item.Name" /><br />
            <h3><a href="@item.Url">@item.Name</a></h3>
        </div>
    }
    

    Thanks, Dan.

  • Keith R Hubbard 175 posts 403 karma points
    Oct 15, 2014 @ 05:53
    Keith R Hubbard
    0

    no need for a if statement.

Please Sign in or register to post replies

Write your reply to:

Draft