Coder Social home page Coder Social logo

Comments (3)

AaronSadlerUK avatar AaronSadlerUK commented on June 13, 2024 1

Unfortunately not, as everyone renders their menu's different, and so I was unable to come up with a re-usable method

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on June 13, 2024

You would need to do this with a recursive loop with the help of a helper, I don't have an example for that, but below you will see an example for a 2 level navigation.

For example from the demo site a 2 level navigation:

<ul id="nav">
@foreach (var item in umbNav)
{
if (item.Children != null && item.Children.Any())
{
<li>
<a class="@item.CustomClasses" href="@item.Url()" target="@item.Target" rel="@item.Noopener @item.Noreferrer">
@if (item.Image != null)
{
<img src="@item.Image.Url()" alt="@item.Title" width="30" height="30" />
}
@item.Title
@if (item.IsActive)
{
<text>Active</text>
}
</a>
<ul>
@foreach (var child in item.Children)
{
<li>
<a class="@child.CustomClasses" href="@child.Url()" target="@child.Target" rel="@child.Noopener @child.Noreferrer">
@if (child.Image != null)
{
<img src="@child.Image.Url()" alt="@child.Title" width="30" height="30" />
}
@child.Title
@if (child.IsActive)
{
<text>Active</text>
}
</a>
</li>
}
</ul>
</li>
}
else
{
<li>
<a class="@item.CustomClasses" href="@item.Url()" target="@item.Target" rel="@item.Noopener @item.Noreferrer">
@if (item.Image != null)
{
<img src="@item.Image.Url()" alt="@item.Title" width="30" height="30" />
}
@item.Title
@if (item.IsActive)
{
<text>Active</text>
}
</a>
</li>
}
}
</ul>

from our.umbraco.umbnav.

Sven883 avatar Sven883 commented on June 13, 2024

Hey @AaronSadlerUK
Thanks for the quick response!

Ok, I will add this in the code. I thought it would automatically get the children in the 'GetLinkHtml' extension method.

Thanks!

from our.umbraco.umbnav.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.