You can set up the navigation menu in two ways:
Dynamically: Umbraco can automatically generate a navigation menu based on the pages in the Content Tree. When you create or modify a page, it will automatically appear in the navigation menu. This dynamic approach eliminates the need to manually add or update menu items when pages are added, removed, or renamed.
Hardcoded: Alternatively, you can hardcode the navigation menu. However, this approach requires more maintenance, as any changes to the pages—such as adding, removing, or renaming—would need to be manually reflected in the menu.
To create dynamic navigation links from the published content nodes, follow these steps:
Go to Settings.
Expand the Templates folder from the Templating section.
Open the Master template.
Locate the <!-- Navigation -->
tag (around line 20).
Right below it, place the cursor on an empty line.
Select Query builder... in the top-right side of the editor.
Make sure it is set to say "I want all content from my website".
Click Submit.
You now have the following snippet in your Master Template:
This snippet needs to be merged with the navigation above it.
Wrap the <ul>
tag inside the <div class="container">
and <nav>
tags.
The final result will look like this:
Click Save.
To add a basic hardcoded navigation, follow these steps:
Go to Settings.
Expand the Templates folder from the Templating section.
Open the Master template.
Go to the <!-- Navigation -->
tag (around line 20).
Copy the content within the <div>
tags (around line 21 to 43) and replace it with the following code:
Click Save.
The IsVisible() helper method
If you add a checkbox property to a Document Type with an alias of umbracoNaviHide, the IsVisible() helper method can be used to exclude these from being shown in any collection.
Let's test the menu. You'll find that clicking on the Articles link throws an Umbraco error as we've not created this page yet. We'll create the Articles page in the next chapter.