We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Is it possible to chunk results

How Do I?

Fast Eddie's avatar
Fast Eddie
11 posts
6 years ago
Fast Eddie's avatar Fast Eddie

Is it possible to chunk the results of exp:channel:entries ?

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
6 years ago
Robin Sowell's avatar Robin Sowell

I’m not sure what you mean. Can you walk me through what you need to do a bit?

       
Fast Eddie's avatar
Fast Eddie
11 posts
6 years ago
Fast Eddie's avatar Fast Eddie

Hi Robin,

Thank you for helping me out 😊

I was trying to loop through exp:channel:entries and chunk the results similar to php array_chunk.

I was able to get around this by counting and then adding closing and open tags. In my case, I wanted to list 4 entries within a slide on a carousel. sample code:

<div id="fbReviewContent" class="carousel slide testimonials" data-ride="carousel">
    <div class="carousel-inner" role="listbox">

        {exp:channel:entries channel="social_reviews" orderby="title" sort="asc" }

        {if count == '1'}
        <div class="carousel-item text-center active">
            <div class="container-fluid">
                <div class="row mb-5">

        {/if}

                    <div class="col-md-3 p-2">
                        <div class="testimonial text-center py-3 px-1">
                            <h4 class="stars">
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                            </h4>
                            <h4>{title}</h4>
                            <div class="quote">
                                {page_content}
                            </div>
                        </div>
                    </div>

        {if count % 4 == 0}
                </div>
            </div>
        </div>

        <div class="carousel-item text-center">
            <div class="container-fluid">
                <div class="row mb-5">
        {/if}

        {if absolute_count % 4 != 0 && total_results == absolute_count}
                </div>
            </div>
        </div>
        {/if}

        {/exp:channel:entries}

    </div>
</div>

Maybe there is another more cleaver/better ee-way of doing this?

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
6 years ago
Robin Sowell's avatar Robin Sowell

Ah! Makes sense.

And honestly, what you did using the modulus operator is exactly how I would handle your example.

There’s always more than one way to approach things, but yours strikes me as a good first choice. Thanks for sharing it with the next person who wonders!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.