Active tag from menu to project

Hello

I would like to make active links on my menu.php, with tags. Actually, it’s working perfectly when I’m filtering my projects in my projects.php. My menu.php looks like that :

<ul class="tags">
<?php $p = kirby()->request()->params()->tag(); ?>
  <li>
    <a <?php ecco($tag == $p, 'class="active"') ?>  href="<?php echo url('projects')>">← All tags</a></li>
    <?php foreach($tags as $tag): ?>
  <li>
    <a <?php ecco($tag == $p, 'class="active"') ?> href="<?php echo url('projects/' . url::paramsToString(['tag' => $tag])) ?>">
      <?php echo html($tag) ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

I just want to put active class to my tag-links when viewing specific project. For example, you click to one project, and every tags corresponding could be « activated » in the menu.
Am I clear ? You can check my example here :

I will probably edit this post, once finish, to delette the link. Every help will be appreciated, Thanks

You could do something like this:

// get tags of active page
$pageTags = $page->tags()->split();
// check if the tag is in the array of $pageTags
if(in_array($tag, $pageTags)) {
 // class active
}

Thank you for your response, but I can’t make your code work because some code is missing. I’m a newbie, and I don’t know how to integrate if(), and I think a “)” is missing too after $pageTags). Do I have to put <?php before ? I’m so lost, sorry.
Could you please rewrite the code more in detail ? Thx

Try this:

<ul class="tags">
<?php $pageTags = $page->tags()->split(); ?>
<?php $p = kirby()->request()->params()->tag(); ?>
  <li>
    <a <?php ecco($tag == $p, 'class="active"') ?>  href="<?php echo url('projects')>">← All tags</a></li>
    <?php foreach($tags as $tag): ?>
  <li>
    <a <?= in_array($tag, $pageTags)? 'class="active"':'' ?> href="<?php echo url('projects/' . url::paramsToString(['tag' => $tag])) ?>">
      <?php echo html($tag) ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Thank you. I used your code but it doens’t work. I can’t see “active” in the source code into my “a”. I keep hope

Oh, of course $p should be $tag, sorry:

<?= in_array($tag, $pageTags)? 'class="active"':'' ?>

Awesome ! Brillant ! Many thanks !!!
Sorry for the next readers but I have to remove my link !