Copied to clipboard

Flag this post as spam?

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


  • David 14 posts 94 karma points
    Nov 08, 2017 @ 15:23
    David
    0

    Hi all,

    I am working on a umbraco project which has some sections that have have subsections and then content below it, like such:

    Home

    - Event Section

    --- Event Category 1

    ---## Event Item

    ---## Event Item

    --- Event Category 2

    ---## Event Item

    ---## Event Item

    With this I have 3 templates:

    A Main Events Section - showing all events and filtering for category

    A Category Event Section - showing events relating to a category

    The Event Content - showing all details for a individual event

    What I am having trouble with is writing a query that gives me all the individual events to display on the Main Events Section Page and another that gives me all of the events for the Category Event Section which I can display on that page.

    Currently I have only achieved to pull all events related to a defined category and I want to know how I can get results without having to define a category.

    @{      var eventcat = Model.Content.Site().FirstChild("eventMain").FirstChild("eventList").Children()
                                        .Where(x => x.IsVisible());
                }
    
                @foreach(var item in eventcat){ @item.name }
    

    *event main is the main section and event list is the categories

    Can anyone point me in the right direction to achieve this?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 08, 2017 @ 15:55
    Dennis Aaen
    0

    Hi David,

    Welcome to our :)

    Can you please try to do it like this and see if this works for you.

      @{      
    
      var eventcat = Model.Content.Site().FirstChild("eventMain").FirstChild("eventList");
    
      }
        @foreach(var item in eventcat.Children.Where(x => x.IsVisible()){ 
                   @item.name 
        } 
    

    Hope this helps,

    /Dennis

  • David 14 posts 94 karma points
    Nov 13, 2017 @ 16:03
    David
    0

    HI Dennis,

    Thank you for your reply, The solution you have gave me only seemed to return the content for one category, How would I be able to find content for all category's under my section?

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Nov 14, 2017 @ 08:50
    Steve Morgan
    100

    Would this work?

    @{

          var eventItems = Model.Content.Site().FirstChild("eventMain").Descendants("eventItem");
    
    
            foreach (var eventItem in eventItems.Where(x => x.IsVisible()))
            { 
                       <p>@eventItem.Name</p> 
            } 
    }
    
  • David 14 posts 94 karma points
    Nov 14, 2017 @ 11:02
    David
    0

    Worked like a treat! Thank you so much!

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Nov 14, 2017 @ 11:15
    Steve Morgan
    0

    No problem!

    These are pretty handy to get "ideas" of how to traverse nodes (Razor cheat sheets) but by all means keep asking questions until it all clicks!

Please Sign in or register to post replies

Write your reply to:

Draft