Menu dropdown question

Hi everyone,

I am struggling with the following:

I made a menu and it almost works.

  <ul class="menu">
    <?php foreach($pages->visible() as $p): ?>
    <li>
      <a class="al has-dropdown <?php e($p->isOpen(), ' active') ?>" href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>

      <?php if($p->hasVisibleChildren()): ?>
      <ul class="submenu ">
        <?php foreach($p->children()->visible() as $p): ?>
        <li>
          <a href="<?php echo $p->url() ?>" class="al  <?php e($p->isOpen(), ' active') ?>"><?php echo $p->title()->html() ?></a>
        </li>
        <?php endforeach ?>
        <div class="cf"></div>
      </ul>
      <?php endif ?>

    </li>
    <?php endforeach ?>
  </ul>

The problem now is that every menu item a dropdown sign has even when there is no submenu. I know this has to do with the: “has-dropdown” class but can’t get it working. Can anybody help me?

Thanks!

You probably need to do the same trick as the active class, but instead test for children…

<?php e($p->hasVisibleChildren(), ' has-dropdown') ?>

So that line becomes

<a class="al <?php e($p->hasVisibleChildren(), ' has-dropdown') ?> <?php e($p->isOpen(), ' active') ?>" href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
1 Like

On a side note (unrelated to your problem), you should probably update all references to visible/invisible etc with listed/unlisted, since visible etc. was deprecated in Kirby 3.

1 Like

Hi @jimbobrjames thank you for your help!

I’ll change al references. Thank you!