Limiting number of Tags

Hey people :wink:

I try to figure out how to limit the output of tags…



return function ($page) {
    return [
        'tags' => page('any-page')->tags()->split(','),


<?php foreach ($tags->limit(x) as $tag): ?>
<?php endforeach ?>

This doesn’t work :wink:
Hope you can help me!

THX once again.

$tags is a simple array, so use standard PHP array_slice() PHP: array_slice - Manual


thanks for your answer but I can’t handle this ;(
Iam not a pro in PHP. So please can you explain it a little bit more detailed?

  $tags = array_slice($tags, 0, 5);

Alternative: Create a collection from the tags

$tags = new \Kirby\Toolkit\Collection($tags);

 foreach($tags->limit(5) as $tag) {
   echo $tag; 

Big THX.