Orit
Active member
Hi
I have a finder for some categories and I want to shuffle the results and limit them.
Since I don't want to always return the first x of the results, I am not limiting in the finder itself.
My code is as follows:
I am wondering if there is a better (built in maybe?) way to do so?
(I did not find a way to do so through the template. Is there a way to limit results in a for loop inside the template?)
Thanks!
I have a finder for some categories and I want to shuffle the results and limit them.
Since I don't want to always return the first x of the results, I am not limiting in the finder itself.
My code is as follows:
PHP:
$categoryFinder = $this->finder('****')
->where('category_id', $categoryIds);
$categories = $categoryFinder->fetch();
$categories = $categories->shuffle();
$categories = $categories->slice(0, $limit);
I am wondering if there is a better (built in maybe?) way to do so?
(I did not find a way to do so through the template. Is there a way to limit results in a for loop inside the template?)
Thanks!