Copied to clipboard

Flag this post as spam?

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


  • ds 191 posts 223 karma points
    Jun 11, 2012 @ 14:50
    ds
    0

    Filter by date?

    I try to display last added 6 event item by creation date under event node. Any help much appreciated.

    @{
     
      <h3 class="p3-1">Events</h3>
      
      var eventsNode = @Model.NodeById(1058);
      int currentNumber = 1;

    <div class="wrapper">
      @foreach(var eventsItem in eventsNode.Children.InGroupsOf(3))
                {
                     var cssClass="";
                     if(currentNumber == 4)
                     {
                       cssClass="col-4 last-item";
                     }
                     else
                     {
                       cssClass="col-4";
                     }
                 <div class="@cssClass">
                    <div class="indent-right4">
                      <ul class="footer-list">
                        @foreach(var eventsGroup in eventsItem.Children.OrderBy("CreateDate desc"))
                        {
                          if(currentNumber == 3 | currentNumber == 6)
                          {
                            <li class="last-item"><a href="@eventsGroup.Url">@eventsGroup.Name</a></li>
                          }
                          else
                          {               
                            <li><a href="@eventsGroup.Url">@eventsGroup.Name</a></li>
                          }
                          currentNumber++;
                        }
                    </ul>         
                  </div>
                </div>             
                }
     </div>            
    }
  • Grant Thomas 291 posts 324 karma points
    Jun 11, 2012 @ 14:58
    Grant Thomas
    0

    Didn't you have any luck with `OrderByDescending`, omitting the text directive of direction? You may also need to tweak the property name a little (CreateDate is just an alias of sorts, UtcCreated (or something like that, take a look at the Content type (maybe need to drill down into ITypedEntity)) is the 'real' name. But, worth noting, Linq stuff doesn't really work inherently with 'attached', proper properties... mostly just document type properties and those supported by specific coding in the core).

  • ds 191 posts 223 karma points
    Jun 11, 2012 @ 15:04
    ds
    0

    What I tried in foreach loop actually

     @foreach(var eventsItem in eventsNode.Children.Take(6).OrderBy("CreateDate desc"))

    I tried without luck but I get the following error

    Error Loading Razor Script (file: List News Of6 Item) Cannot implicitly convert type 'umbraco.MacroEngines.DynamicNode' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)    at CallSite.Target(Closure , CallSite , Object )

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 12, 2012 @ 07:13
    Fuji Kusaka
    0

    Can you try something like 

    @inherits umbraco.MacroEngines.DynamicNodeContext @{
     
      var eventsNode = @Model.NodeById(1058);
    var items = eventsNode.Children.OrderBy("createDate desc");
      int currentNumber = 1;
      @foreach(var eventsItem in items.InGroupsOf(3))
                {
                   
                       
                }          
    }
    @foreach(var eventsGroup in eventsItem.Children)
                        {
                          if(currentNumber == 3 | currentNumber == 6)
                          {
                            <li class="last-item"><a href="@eventsGroup.Url">@eventsGroup.Name</a></li>
                          }
                          else
                          {              
                            <li><a href="@eventsGroup.Url">@eventsGroup.Name</a></li>
                          }
                          currentNumber++;
                        }

    If any not mistaken you should be ordering the first part that is the EventNode and remember to inherit the @inherits umbraco.MacroEngine.

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft