N3riu2
1
Hey people ![:wink: :wink:](https://emoji.discourse-cdn.com/apple/wink.png?v=12)
I try to figure out how to limit the output of tags…
controller:
<?php
return function ($page) {
return [
'tags' => page('any-page')->tags()->split(','),
];
};
template:
<?php foreach ($tags->limit(x) as $tag): ?>
…anything…
<?php endforeach ?>
This doesn’t work ![:wink: :wink:](https://emoji.discourse-cdn.com/apple/wink.png?v=12)
Hope you can help me!
THX once again.
texnixe
2
$tags
is a simple array, so use standard PHP array_slice()
PHP: array_slice - Manual
N3riu2
3
Hey,
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?
texnixe
4
$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;
}