Moodle Themes | Totara Themes | Hierarchical Structure

| By Webner

In one of our Totara theme projects, we wanted to display the categories->subcategories->courses structure dynamically up to any level. In Totara a category can have subcategories, each subcategory can have its own set of subcategories and so on up to any level. Also Courses can appear at any category level (like each category or subcategory can have courses). We needed to pull all of this information in advance, show only top level categories and courses initially on web page, onclick of a category show next level of subcategories and courses and so on. By prefetching the information, although page load may be a little slow but after that performance of loading next level is very fast. To fetch the categories and courses upto N levels deep was a recursive process. These are the steps:

Firstly, we fetched top categories and courses and displayed them.

Then for each top level category we called three functions:


In displaySubCategories(categoryName), we fetched subcategories of passed category, displayed them (in a hidden div), in displayCourses(categoryName) we displayed courses of passed category, displayed them (in a hidden div) and in displaySubcategoriesRecursively(categoryName) we followed same procedure for each subcategory of categoryName recursively (means for each subcategory of categoryName we called above 3 functions and so on). That way we pre-loaded all the information in hidden DIVs and then toggled their display based on user clicks.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need LMS app development or any other software development assistance please contact us at

Leave a Reply

Your email address will not be published. Required fields are marked *