I am trying to create a Dynamic Left Navigation using Umbraco 12.
I created a page type called Content Page (alias contentPage) that has 2 compositions Content and Page Settings
In Page Settings, I added 2 fields the 1st one is called "Show on Left Nav" (which is a true or false) this field will be to determine if the page will show as a link on the left navigation.
The 2nd one is called Left Nav Section (alias leftNavigationSection) (Which is a dropdown with the values for the different sections that will have different navigations) - This one will determine what section the page belongs to
Here is an example of what the data will look like
- Home
- Human Resources (Show in Left Nav Y and Section Human Resources)
-
- Employee Forms (Show in Left Nav Y and Section Human Resources)
-
- Budget (Show in Left Nav N and Section Human Resources)
-
- Employee Info (Show in Left Nav N and Section Human Resources)
-
- Documents (Show in Left Nav N and Section Human Resources)
when you visit any of the pages under the Human Resources section (Employee Forms, Documents, etc. ) The query should return the links
- Human Resources
-
- Employee Forms
because they belong to the "Human Resources" section and the left nav setting is yes
While the links for
- Budget
- Employee Info
- Documents
should be hidden from the left nav because the left nav setting is No
No matter what page in the "Human Resources" section you are viewing you should load all the visible links for the section the page belongs to
This is the query I have so far
var selectLeftNav = Model.Ancestor()
.Children<ContentPage>()
.Where(x => x.IsVisible())
.Where(x => x.ShowOnLeftNavigation == true)
.Where(x => x.LeftNavigationSection == "Human Resources");
<ul class="nav left-nav-items">
@foreach (var item in selectLeftNav)
{
<li class="nav-item"><a href="@item.Url()">@item.Name</a></li>
}
</ul>
The value for Model.Value("leftNavigationSection") comes from a Dropdown and I can print it to the screen without any issues
In conclusion, I am trying to read the setting for the page the user is on and based on that value show the left navigation items that are the same ..
Over all I am asking, How can I build my own query based on a parameter I am adding all my to all my content types. (without using the query builder that generates a GUID)
Typically, when using the "Ask a question" feature on StackOverflow (or anywhere else for that matter), at least part of what you write should be in the form of an actual question. But let's just assume that the code you have included isn't working as intended?
For anyone to be able to help, you should include as many details as possible as to:
TL;DR: could you please update the "question" with more details?