Keep the filter link in project link

Hey,

i managed to build a filter system for all pages in a projects folder. The client can create tags which get listed and are clickable and adds “tag:Selected” (for example) to the url. all projects that have a Video Tag are getting listed. The project that is getting shown is on the right so the filter menu is visible all the time. It looks like this and is basically working fine:

<div class="menu">
    <h2>Projects</h2>
    <div>
      <?php $type = $site->find('works')->children()->listed()->pluck('Type', ',', true); ?>
      <?php foreach($type as $tag): ?>
        <a href="<?= url('works', ['params' => ['tag' => $tag]]) ?>">
          <?= urldecode($tag) ?>
        </a>
      <?php endforeach ?>
      <a href="<?= $site->url() ?>">All</a>
    </div>
  </div>

  <div>
    <?php $projects = $site->find('works')->children()->sortBy()->filterBy('Type', param('tag'), ',');?>
    <?php
      if($tag = param('tag')):
      foreach( $projects as $project):
    ?>
      <a href="<?= $project->url() ?>">
        <div class="project-list-grid">
            <p><?= $project->title() ?></p>
            <p><?= $project->Client() ?></p>
            <p><?= $project->Year() ?></p>
        </div>
      </a>
      <?php endforeach ?>
  </div>

However when a project is clicked the filter jumps back to not filtered and the url goes from
/works/tag:Selected
to
/works/project-1
obviously because thats the link that is set when the project was created

But It should be
/works/tag:Selected/project-1

Is there a way to accomplish this? To keep the filter when clicking a filtered project?

Any help very much appreciated! Thank youuu!
Julius

I must admit I don’t quite get your setup. Are you loading the single projects into the parent page via Ajax or something like this?

I go into the “works” directory and fetch all children, which have tags which are listed and clickable and direct to the url which has a “tag:…” at the end.
I don’t load anything with Ajax or so. I think i build the filter like it was built in one of the kirby cookbooks.

Hey again,
i found a quick and easy solution:
i just put “/tag:<?= $tag ?>” behind the link of the project that should keep the filter active.

Now i wonder how i can add the class “active” to the above filter menu:
tried a few things but didn’t work :frowning:

<div>
    <?php $type = $site->find('works')->children()->listed()->pluck('Type', ',', true); ?>
    <?php foreach($type as $tag): ?>
      <a href="<?= url('works', ['params' => ['tag' => $tag]]) ?>">
        <?= urldecode($tag) ?>
      </a>
    <?php endforeach ?>
    <a href="<?= $site->url() ?>">All</a>
</div>

Best,
Julius