Copied to clipboard

Flag this post as spam?

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


  • David 7 posts 87 karma points
    15 days ago
    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 4250 posts 17245 karma points admin hq c-trib
    15 days ago
    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 7 posts 87 karma points
    1 week ago
    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 780 posts 2290 karma points c-trib
    1 week ago
    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 7 posts 87 karma points
    1 week ago
    David
    0

    Worked like a treat! Thank you so much!

  • Steve Morgan 780 posts 2290 karma points c-trib
    1 week ago
    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