URL problem with tag filtering

#21

I see… the code driving the tag list looks like this…

<div class="categories">
  <div class="draw">
    <div class="block-col">
      <a href="<?= $site->index()->find($section)->url() ?>" class="<?php if(!$param = urldecode(param('tag'))) {echo "active";} ?>">All</a>
    </div>
    <?php foreach($tags as $tag): ?>
    <div class="block-col">
      <a <?php e($tag == $currenttag, ' class="active"') ?> href="<?= url($section, ['params' => ['tag' => $tag]]) ?>">
        <?= html($tag) ?>
      </a>
    </div>
    <?php endforeach ?>
  </div>
</div>
#22

if you inspect the the element in dev tools, you see that there’s no encoding happening.

<div class="block-col">
      <a href="https://hashandsalt.com/work/tag:Web Design">
        Web Design      </a>
    </div>
#23

Hrmm. I guess the problem is in the controller after all then, since its getting $tags from the controller?

#24

No, sorry, I just remember that the param code above only takes care of the separator, not of the value encoding.
Your code should be

['params' => ['tag' => urlencode($tag)]

The controller is OK. You need to decode in the controller what you encode in the link in your template.

#25

Thats better :slight_smile: I had to do it in another place as well to make the $currenttag active class happy.

<a <?php e(urlencode($tag) == $currenttag, ' class="active"') ?> href="<?= url($section, ['params' => ['tag' => urlencode($tag)]]) ?>">
  <?= html($tag) ?>
</a>

Solved :slight_smile: Thanks Sonja.