Hello all,
My first forum post. Totally loving the Kirby CMS.
I am building a template similar to the projects/project structure.
We are gonna have ~30 projects, all must be visible. This is not a problem, I found where to change the loop limit, adjust the css for >3 etc.
Problem: I also see all the projects in the menu dropdown, this is not what I want.
When I de-activate the “visible in menu” property for the project, it also disappears from the projects loop.
Thankful for all help.
If you don’t want any submenu, you can just remove the submenu from the menu.php snippet:
<nav role="navigation">
<ul class="menu cf">
<?php foreach($pages->visible() as $p): ?>
<li>
<a <?php e($p->isOpen(), ' class="active"') ?> href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
</li>
<?php endforeach ?>
</ul>
</nav>
If you want to keep the submenu for other pages with submenus, you can use an if-statement:
<nav role="navigation">
<ul class="menu cf">
<?php foreach($pages->visible() as $p): ?>
<li>
<a <?php e($p->isOpen(), ' class="active"') ?> href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
<?php if($p->hasVisibleChildren() && ! $p->is(page('projects'))): ?>
<ul class="submenu">
<?php foreach($p->children()->visible() as $p): ?>
<li>
<a href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
</nav>
That’s an awesome idea That would totally work.
However, I realized I was not clear enough.
Let me demonstrate what I need:
Level 1 menu: $Page about projects (visible)
Level 2 submenu: $Projects (dropdown visible)
Level 3 sub-submenu: $Project (dropdown not visible)
So I would need a slightly more complex logic for your example.
I tested to
a)
<?php if($p->hasVisibleChildren() && ! $p->is(page('projects')->children())): ?>
and
b)
<?php if($p->hasVisibleChildren() && ! $p->is(page('project'))): ?>
But both returns a blank menu.
Never mind. Now it justs works somehow
That’s a classic.
“It’s not working - I don’t know why.”
“It’s working - I don’t know why.”
Glad you sorted it out yourself . You can help to improve our answers by providing your code snippet that does not work as expected next time … I was (wrongly) assuming you were trying to adapt the code from the starterkit. Thank you!
Oh, and one more thing: Code blocks are more readable when wrapped with three back ticks on separate lines.
I was impressed by the example code you gave me.
It was working very nice.However, when I re-defined my own problem, I realized there was one level deeper child grandchildren situation.
And in this scenario the starterkit menu did the job perfectly.
So it seems that was already built.
I will markup the example code blocks better next time.
Thanks!