Hi,
I have some problems to render my navigation without drafts. Is there an easy example snippet somewhere to understand why drafts are always rendered?
Or whats wrong with my code?
<ul class="nav-vertical first-level">
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
{{ if .HasChildren }}
<li class="{{ if $currentPage.HasMenuCurrent "main" . }}active{{ end }}">
<a href="{{ .URL }}">{{ .Name }}</a>
<ul class="second-level">
{{ range .Children }}
<li class="{{ if $currentPage.HasMenuCurrent "main" . }}active{{ end }}">
// here the link
</li>
{{ end }}
</ul>
</li>
{{ else }}
<li class="{{ if $currentPage.HasMenuCurrent "main" . }}active{{ end }}">
// here the link
</li>
{{ end }}
{{ end }}
</ul>
You added those items to the main menu from your config.toml. Since those menu items aren’t from pages, they aren’t affected by the range, hence the confusion.… sorry, I mistyped there.
When you are range over the main menu, it gets all the menu items. Then, you start filtering them by conditionals, but the items you set in your config aren’t included, hence the reason they show up at all times.
You’ll have to re-think how you build that menu.
I’m not sure what you are trying to do. Aside from the draft status of the items in question, the menu looks good. The original question was about draft status, and we know that isn’t the issue, so could you clarify what you are trying to do?
Thank you for your help - I thought that the draft status is considered when I create the menu from config.toml - this is not the case, isn’t it?
I read now the docs and I think I should try to create the menu from front matter.
It is not the case. And that is useful, because you can add any links to the menu from config. You could put your email as a menu item, or link to other sites you run. That sort of thing.
Hmm, it’s not that easy. I think i didn’t understand some concepts of rendering menus and managing content. I created a new theme for testing purposes - just for the menu. And the output was not what I expected.
Look at that screenshot - why is it not possible to render the content with subcontent as unordered list??