Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub menus based on pages that are child pages of another one #109

Open
traustitj opened this issue Nov 23, 2024 · 0 comments
Open

Sub menus based on pages that are child pages of another one #109

traustitj opened this issue Nov 23, 2024 · 0 comments

Comments

@traustitj
Copy link

traustitj commented Nov 23, 2024

I am not sure how I can post a small code to help with Piranha. If this is not the right way, please tell me how. I think having a PR on the full project is a bit much.

Here is a code which implements sub menu drop downs.

<div class="collapse navbar-collapse" id="navbarsExampleDefault">
    <ul class="navbar-nav ml-auto">
        @foreach (var item in (await WebApp.Site.Sitemap.ForUserAsync(User, Auth)).Where(i => !i.IsHidden))
        {
        <li class="nav-item@(item.Id == WebApp.PageId || item.HasChild(WebApp.PageId) ? " active" : "")">
            @{
                var subPages = WebApp.Site.Sitemap.GetPartial(item.Id);
                if (subPages != null && subPages.Count > 0)
                {
                    <div class="dropdown">
                        <a href="#" class="dropdown-toggle nav-link" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">@item.MenuTitle</a>
                        <div class="dropdown-menu" aria-labelledby="dropdownMenuLink" v-bdropdown>
                            @foreach (var subPage in subPages)
                            {
                                <a class="nav-link" href="@WebApp.Url(subPage)">@subPage.MenuTitle</a>
                            }
                        </div>
                    </div>
                } else
                {
                    <a class="nav-link" href="@WebApp.Url(item)">@item.MenuTitle</a>
                }
            }
        </li>
        }
    </ul>
</div>

It replaces code in the _Layout.cshtml

It also shows correctly the active page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant