Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    Jul 15, 2012 @ 14:53
    Daniel Larsen
    0

    News list on every page

    Hi, I am trying to make a news list that will be on every single page, but I am no razor wizard like most of you guys. My site layout looks like this:

    Language

    --- Front

    --- Page 1

    --- Page 2

    --- Page 3

    --- NewsList

    --- --- Item 1

    --- --- Item 2

    --- --- Item 3

    This is what I have got so far:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var lang Model.AncestorOrSelf("Language");
        var news lang.NewsList;
      }
              
    <ul>
        @foreach (var item in @news.Children)
        {
            <li><href="@item.Url">@item.Name</a></li>
         }
    </ul>

    If you need more information, you shall have it!

    Thank you :-)

  • gilad 185 posts 425 karma points
    Jul 15, 2012 @ 15:21
    gilad
    0

    Hi Daniel.

    See that NewsList is not a property of "Language" so for getting all news item you should do something like that : 

    var news = Model.AncestorsOrSelf("Language").Descendants("News-item-alias");

     

    @foreach (var item in @news)
        {
            <li><href="@item.Url">@item.Name</a></li>
         }

     

    If you want to get the news folder Node and run trow children you could do domething like that : 

    var news = Model.AncestorsOrSelf("Language").Descendants("News-folder-alias").First();

    @foreach (var item in @news.Children)
        {
            <li><href="@item.Url">@item.Name</a></li>
         }

     Hope that help.

    Cheers

     

  • Daniel Larsen 116 posts 381 karma points
    Jul 15, 2012 @ 18:41
    Daniel Larsen
    0

    I would like to say that it worked, but no :-( I tried both solutions, but still nothing. The alias for the news page is "NewsList" and its childrens alias is "News"

    Thank you for the quick response! :-)

  • gilad 185 posts 425 karma points
    Jul 16, 2012 @ 08:08
    gilad
    0

    What do you get?

    try this : 

    @{
    var news = Model.AncestorOrSelf("Language").Descendants("News-item-alias");
     
       foreach
     
    (var item in news)
       {
           <li><href="@item.Url">@item.Name</a></li>
       }

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 16, 2012 @ 08:15
    Fuji Kusaka
    1

    Hi Daniel,

    Try using the nodeById 

     

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var newsItems = Model.NodeById(NewsListNodeID); //add the NodeId of NewsList Here
      var sortedItems = newsItems.Children.OrderBy("createDate descending");
      foreach(var page in sortedItems.Where("visible"))
      {
         <li><a href="@page.Url" title="@page.Name">@page.Name</a></li>
       }  
    }

    This should get you working

     

    //fuji

  • Daniel Larsen 116 posts 381 karma points
    Jul 17, 2012 @ 12:54
    Daniel Larsen
    0

    Thanks gilad, it works! :-) And thank you Fuji for the response :-)

Please Sign in or register to post replies

Write your reply to:

Draft