Copied to clipboard

Flag this post as spam?

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


  • Chris 32 posts 108 karma points
    Dec 31, 2014 @ 15:13
    Chris
    0

    Get Document Type values in Layout Template

    Hi again,

    Great support early thanks! Got another query that I can't seem to find the answer to. In my layout (master) template I want to display the latest new items in the footer. Here is what I am trying to do (using MVC now rather than macros)

    @foreach (var page in Model.Content.AncestorOrSelf(1).Children.Where(x => x.DocumentTypeAlias == "umbNewsItemDT"))
                                { 
                                    <li class="media"><a href="#" class="media-date">19<span>FEB</span></a>
                                        <h5 class="media-heading"><a href="#">@page.newsTitle</a></h5>
                                        <p>@page.newsSummary</p>
                                    </li>
                                }
    

    Any pointers appreciated. Thanks.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 31, 2014 @ 15:42
    Jeavon Leopold
    0

    Hi Chris,

    If you change Children to Decendants then it should work however it would be more effecient to find the parent news node first, does it have a unique document type alias?

    Jeavon

  • Chris 32 posts 108 karma points
    Dec 31, 2014 @ 15:59
    Chris
    0

    Thanks Jeavon. Yes it has the documenttypealias of 'umbNewsItemDT'. How might I go about doing that?

    Chris

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 31, 2014 @ 16:26
    Jeavon Leopold
    0

    Ok, in that case I think you almost have it, try this

    @foreach (var page in Model.Content.AncestorOrSelf(1).Children.FirstOrDefault(x => x.DocumentTypeAlias == "umbNewsItemDT").Children)
    
  • Chris 32 posts 108 karma points
    Dec 31, 2014 @ 16:31
    Chris
    0

    Getting the error

    Compiler Error Message: CS0446: Foreach cannot operate on a 'method group'. Did you intend to invoke the 'method group'?

    enter image description here

  • Chris 32 posts 108 karma points
    Dec 31, 2014 @ 17:01
    Chris
    0

    Managed to sort it I think using

        @{
        var page = Umbraco.Content(1094);
    }
    
    
    @foreach (var child in page.Children) { 
       <li class="media"><a href="#" class="media-date">19<span>FEB</span></a>
                                            <h5 class="media-heading"><a href="#">@child.NewsTitle</a></h5>
                                            <p>@child.NewsSummary</p>
                                        </li>
    }
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 31, 2014 @ 21:53
    Jeavon Leopold
    0

    Ah ok, you're using the dynamic CurrentPage model, then this is probably what your after

    @foreach (var page in CurrentPage.AncestorOrSelf(1).umbNewsItemDTs.First().Children)
    
  • 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