Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:03:32+00:00 2026-06-09T17:03:32+00:00

We have a data structure in sitecore that features the same templates at the

  • 0

We have a data structure in sitecore that features the same templates at the same ‘depth’. We are making classroom content that features units, lessons, and activities in the following structure:

Unit 1
-- Lesson 1
---- Activity 1
---- Activity 2
-- Lesson 2
---- Activity 3
---- Activity 4
Unit 2
-- Lesson 3
---- Activity 5
---- Activity 6
-- Lesson 4
---- Activity 7
---- Activity 8

and so on. When I am on an activity item, I want to return the next activity item in that particular unit, and return null if there are no more activities in that unit.

The best I have been able to do so far is to target the current activities unit ancestor (easily found) and get all activities that are under it, then loop through all of them to get prev/next activities. It seems like there must be a better way to accomplish this, so I thought I’d throw it out here for ideas.

Current Code

Item unit = Sitecore.Context.Item.Axes.SelectSingleItem("ancestor-or-self::*[@@templatename='Unit']");
Item[] allActivities = unit.Database.SelectItems("ancestor-or-self::*[@@templatename='Activity']");

foreach(Item thisitem in allActivities){
    //Process here
}

Siblings (“Following” & “Preceeding”) dont work because it only returns direct siblings underneath the same lesson, not the unit as needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:03:33+00:00Added an answer on June 9, 2026 at 5:03 pm

    I think you have the right idea. A few things to take note of:

    1. unit.Database.SelectItems() starts at the root of unit’s Database and doesn’t use the unit as the starting context. If you intend to traverse downwards to the get all Activities for that unit, you’ll need to use unit.Axes.SelectItems()

    2. Depending on the number of Activity items per unit, you may want to consider using sitecore fast query or possibly Lucene to handle the selection.

    Here is an example of how to handle the previous/next logic. The use of .FirstOrDefault() will return null if/when a previous or next sibling isn’t available.

    Item unit = Sitecore.Context.Item.Axes.SelectSingleItem("ancestor-or-self::*[@@templatename='Unit']");
    Item[] unitActivities = unit.Axes.SelectItems("descendant::*[@@templatename='Activity']");
    // The order of 'unitActivities' defaults to the order that items appear in Sitecore tree.
    // Perform additional sorting here if needed
    
    var nextActivity = unitActivities.SkipWhile(i => i.ID != Sitecore.Context.Item.ID).Skip(1).FirstOrDefault();
    var prevActivity = unitActivities.Reverse().SkipWhile(i => i.ID != Sitecore.Context.Item.ID).Skip(1).FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure in my C++ program that has some attributes of
I have a data structure that looks like this: data =[ {'key_1': { 'calc1':
I have a data structure that looks like this: Model Place primary key id
I have a Sitecore content structure where any single item can have a number
I have a data structure (created from a YAML document) that looks like this:
I have a data-structure such that: SecurityPolicy 1<---* SecurityPolicyRule Therefore, a SecurityPolicy can have
I have a data-structure (in plist) that looks something like this: What i have
I have a data structure that looks like [(hello, 12), (yo, 30)] . How
I have a data structure that represents a directed graph and I'm looking for
I have a data structure that stores amongst others a 24-bit wide value. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.