Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Yaco Zaragoza 88 posts 362 karma points
    Mar 06, 2024 @ 20:11
    Yaco Zaragoza
    0

    Building a Custom Query

    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

    1. Home Human Resources (Show in Left Nav Y and Section Human Resources)
    2. Employee Forms (Show in Left Nav Y and Section Human Resources)
    3. Budget (Show in Left Nav N and Section Human Resources)
    4. Employee Info (Show in Left Nav N and Section Human Resources)
    5. 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

    1. Human Resources
    2. Employee Forms

    because they belong to the "Human Resources" section and the left nav setting is yes

    While the links for

    1. Budget
    2. Employee Info
    3. 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)

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft