docs icon indicating copy to clipboard operation
docs copied to clipboard

Add docs for chunking in Antlers

Open jasonvarga opened this issue 1 year ago • 4 comments

Applies to the collection tag but also could be assets fields etc.

For https://github.com/statamic/cms/pull/9157

Dumping stuff I tested with:

{{? $chunked_count = 0 ?}}
{{ field chunk="3" }}
<div class="border p-4 mb-4">
    <b>Chunk {{ count }}/{{ total_chunks }}/{{ total_items }}</b>
    {{ chunk }}
    {{? $chunked_count++ ?}}
    <li><a href="{{ url }}" class="text-teal font-medium text-lg mb-4">{{ title }}</a> ({{ chunked_count }}/{{ total_items }})</li>
    {{ /chunk }}
</div>
{{ /field }}

Where {{ field }} is either {{ collection:some_collection }} or {{ some_query_builder }} (like an assets fields).

chunked_count is a way to count items across chunks as count in a chunk would only go 1-2-3-1-2-3-1-2-3...

CleanShot 2024-03-22 at 10 57 16

jasonvarga avatar Mar 22 '24 14:03 jasonvarga

Added in #1473

miicah avatar Feb 20 '25 03:02 miicah

I've just had a quick look... I can't see where this was added. I can see the docs for the chunk modifier (but that's a slightly different thing).

Maybe I missed something though - that diff is pretty large! 😄

duncanmcclean avatar Feb 20 '25 10:02 duncanmcclean

Probably a misunderstanding on my part, but I can't see the difference between what the chunk modifier does using that example and the code example here.

The only thing I can see that's missing is documentation around chunk_key.

miicah avatar Feb 20 '25 11:02 miicah

They look similar, but they are slightly different.

One lets you chunk items in an array, and the other lets you chunk items from a query builder (which is what you're dealing with in the {{ collection }} tag).

We probably need to add an example of the chunk parameter to the collection/taxonomy tag docs.

duncanmcclean avatar Feb 20 '25 13:02 duncanmcclean