-
How would you do it: 2 levels menu
February 9, 2015 Rodrigo Peplau 1
One of our clients has a development team that will take over the project as soon as we finish our part. They have great developers with no Sitecore experience, and some of their questions are pretty valuable for those starting in the Sitecore world. My answer that follows has a consultancy approach, providing explanations and advises at a higher level.
Here is the question:
In Sitecore, how would you organize architecture and static files – mainly CSS and javascript files – during development of the following two levels menu?
The first level shows an Image and a Title and starts closed:

When the user hovers a block at Level 1, a second part is displayed showing items on Level 2:

Answer
Your static CSS and Javascript files, like in any other web application, must be loaded somehow. At the project we are working, we have a bundle and minification process in place, responsible for loading, minify’ing and caching the files so everything loads faster.
But you can load files the old way:
<script src="myscript.js" type="text/javascript"></script>
The implementation itself can be split into two different challenges:
- Front-end development
We clearly have a good front-end work here, some dynamic behavior when user hovers around level 1, the look and feel and everything. Basically all HTML markup, javascript and css stylesheets can be prepared without having Sitecore specifically in mind; - Back end development
All necessary to enable the content edition of menu items, and make it work dynamically at a page, including:- Step 1 - Upload your javascript and CSS files somewhere at your site filesystem (Eg: “/assets/js” and “/assets/css“), then load them somehow (traditional, bundle, etc);
- Step 2 - Define your data structure (templates and fields) to support the content management. It all depends on your requirements – let’s have the following two possible scenarios:
- Scenario 1 - You may want to feed the menu with pages and subpages you already have in your content tree. In this case you would just use your existing data:

- Scenario 2 - Or you may be asked to create a dedicated data structure, not pages themselves but pointing to real pages. This data structure would have the following format:
Menu Item Level 1
Menu Item Level 2
And you would keep the item somewhere outside your page’s content tree:

- Scenario 1 - You may want to feed the menu with pages and subpages you already have in your content tree. In this case you would just use your existing data:
- Step 3 - Create the component/sublayout that implements the menu feature. Following the same two scenarios above:
- Scenario 1 - In this case you would use the Sitecore API to pragmatically get the Home item, using Children items to render menu’s level 1, and their grandchildren rendering level 2:
var homeItem = Sitecore.Context.Database.GetItem("/sitecore/content/Home"); var levelOne = homeItem.Children.ToList(); foreach (var itemLevelOne in levelOne) { // This item represents a Level 1 menu block var title = itemLevelOne.Fields["Title"].Value; var image = itemLevelOne.Fields["Image"].Value; var levelTwo = itemLevelOne.Children.ToList(); // ... do whatever you need with Level 1 foreach (var itemLevelTwo in levelTwo) { // Here you work your Level 2 item var titleLevelTwo = itemLevelTwo.Fields["Title"].Value; } } - Scenario 2 - This implementation would be very similar to the first scenario, except that you would have to start at your repository folder (Eg: /sitecore/content/Lists/Menu) instead of the Home item.
- Scenario 1 - In this case you would use the Sitecore API to pragmatically get the Home item, using Children items to render menu’s level 1, and their grandchildren rendering level 2:
Categories: Architecture, Development, How To
Tags: Architecture, Development, How To
Sitecore Environments for Dev, QA, UAT and Production Sitecore 7.5 and MongoDB through different environments
One thought on “How would you do it: 2 levels menu”
Leave a Reply to Rodrigo Peplau Cancel reply
- Front-end development
Proudly 10x Sitecore MVP!
(2016-2025)
Localization
Recent Posts
Recent Comments
- navan on Meet MVPinny: the AI-Powered Sitecore Assistant
- Adriana on Content generation with Sitecore Connect and ChatGPT
- NAVAN on Automatic Sitecore NuGet upgrades with Powershell
- Hedipo S Menezes on Corey Peplau wrote this - WFFM conflict with Unity DI and a lesson on how Sitecore community is so amazing
- Rodrigo Peplau on ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.
Archives
- March 2025
- January 2025
- June 2024
- April 2024
- February 2024
- December 2023
- November 2023
- August 2023
- July 2023
- January 2023
- February 2022
- December 2021
- November 2021
- March 2021
- July 2020
- February 2020
- September 2019
- July 2019
- April 2019
- March 2019
- December 2018
- February 2018
- January 2018
- November 2017
- September 2017
- August 2017
- July 2017
- March 2017
- February 2017
- November 2016
- September 2016
- August 2016
- July 2016
- April 2016
- November 2015
- September 2015
- July 2015
- April 2015
- March 2015
- February 2015
Categories
- Actions
- Active Directory
- Analytics
- Architecture
- Bug fixing
- CDP/Personalize
- ChatGPT
- Content Edition Experience
- Content Hub
- Continuous Integration
- Dev
- Development
- Environments
- Experience Editor
- Experience Forms
- Front-end
- Hackathon
- Health Check builds
- Helix
- How To
- LDAP
- MVP
- MVP Summit
- MVPinny
- Phantom JS
- Powershell
- QA
- Richtext Editor
- Rules
- Security Provider
- SIF
- Sitecore 9
- Sitecore API
- Sitecore Community
- SItecore Connect
- Sitecore Modules
- Sitecore Rocks
- Sitecore Rule Processor
- Sitecore Symposium
- SPE
- SPE-only Alliance
- SPEAK
- SUG
- Support Ticket
- TDS
- Team City
- Uncategorized
- Upgrades
- Visual Studio
- WFFM
- Workflow
- XConnect
- xDB
- XM Cloud
Caro visitante de língua portuguesa: traduzirei meus posts na medida do possível. Caso você precise muito deste conteúdo em português, deixe um recado aqui no mural e priorizarei sua tradução.