coert_g Posted November 15, 2018 Share Posted November 15, 2018 Hey guys, We've built a custom relationship plugin that allows us to pull through items from the gallery application to the pages application, by tying the image to a listing in the pages app. I'm looking to output these items now, and limit them. I can output them fine using the following: {{if $relationships['gallery_images'] == NULL}}No photos available for this listing, be the first to <a href="/gallery/submit/?_new=1">submit a photo</a>.{{else}} {{foreach $relationships['gallery_images'] as $image}} <div class="containThumb"> <div class="thumbBlock_holder"> <img class="myImg thumbBlock" src="/uploads/{$image['image_masked_file_name']}"/> </div> </div> {{endforeach}} {{endif}} But would love some assistance in being able to limit that listing to only show 8 items. Can someone please assist with the logic in these loops to limit the loop to output only 8 results. Thanks! Link to comment Share on other sites More sharing options...
Nathan Explosion Posted November 15, 2018 Share Posted November 15, 2018 {{if $relationships['gallery_images'] == NULL}} No photos available for this listing, be the first to <a href="/gallery/submit/?_new=1">submit a photo</a>. {{else}} {{$i = 0;}} {{foreach $relationships['gallery_images'] as $image}} <div class="containThumb"> <div class="thumbBlock_holder"> <img class="myImg thumbBlock" src="/uploads/{$image['image_masked_file_name']}"/> </div> </div> {{if ++$i == 8}} {{break;}} {{endif}} {{endforeach}} {{endif}} Link to comment Share on other sites More sharing options...
newbie LAC Posted November 15, 2018 Share Posted November 15, 2018 Hello, Quote Breaking and continuing or use array_slice {{foreach array_slice($relationships['gallery_images'], 0, 8) as $image}} but it would be better if you limit result in php. No need to get 1000000 rows if you want display 8 Link to comment Share on other sites More sharing options...
bfarber Posted November 15, 2018 Share Posted November 15, 2018 4 hours ago, newbie LAC said: but it would be better if you limit result in php. No need to get 1000000 rows if you want display 8 ^ This. Why does the array have more than you need? If it's from a database query, for instance, the performance impacts can be significant and the best solution is to use a MySQL LIMIT clause so you only have the 8 results you want in the first place. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.