Style a parent menu-item that has a child

Hi I’m trying to style a parent menu-item that has children differently that menu-items without children. I have used the code from the cook book:

<?php 
$menu = $site->menu()->toStructure();
if ($menu->isNotEmpty()) : ?>
<nav>
  <ul>
    <?php foreach ($menu as $item): ?>
      <?php if ($mainMenuItem = $item->mainMenu()->toPage()) : ?>
      <li><a href="<?= $mainMenuItem->url() ?>"><?= $mainMenuItem->title() ?></a>
      <?php endif ?>
      <?php $subMenu = $item->subMenu()->toPages(); ?>
      <?php if ($item->hasSubmenu()->isTrue() && $subMenu->isNotEmpty()) : ?>
        <ul class="submenu-list">
          <?php foreach ($subMenu as $subItem) : ?>
          <li><a href="<?= $subItem->url() ?>"><?= $subItem->title() ?></a></li>
          <?php endforeach ?>
        </ul>
      </li>
      <?php endif ?>
    <?php endforeach ?>
  </ul>
</nav>
<?php endif ?>

But i would like to style this link

<a href="<?= $mainMenuItem->url() ?>"><?= $mainMenuItem->title() ?></a>

differently when a child page is available. How could I do that?

Hope you can help. Kirby is an awesome cms. Thanks in advance!

You can use the e() helper which will echo a string based on a condition

something like this should do it

class="<?php  e($mainMenuItem->hasChildren(), 'has-children', 'no-children') ?>"

Yes, that works. Thank you!