Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Issue with Collection:ofType

Solved by andrii burkatskyi View solution

Started by andrii burkatskyi 9 years ago · 2 replies · 786 views
9 years ago

Hi!
I want to use collection with choosen template only and i want to paginate it.
I try to use ofType method, but my collection looks strange - like an array which contains empty value or something similar.

Look:

.md file header

YAML
title: Home
content:
    items:
        p[email protected]: /notes
    exclude: topic
    limit: 3
    order:
        by: date
        dir: desc
    pagination: true
--- 

Folder structure:

pages|362x500

And part of template code:

TWIG
{% set collection = page.collection.ofType('note') %}
        {% for child in collection %}
                {% set image = child.media['_header.jpg'] %}
                {% set image = image ? image : child.media.images|randomize|first %}

                {% include 'partials/preview.html.twig'  with {'child': child, 'image':image} %}
                {% if not loop.last %}
                    <div>
                        <hr class="note-hr"/>
                    </div>
                {% endif %}
        {% endfor %}

        {% if config.plugins.pagination.enabled and collection.params.pagination %}
            <div class="pure-g">
                <div class="pure-u-1 text-center">
                    {% include 'partials/pagination.html.twig' with {'base_url':page.url, 'pagination':collection.params.pagination} %}
                </div>
            </div>
        {% endif %}

I thought this collection should contains only 4 elements, and i expected to got only 2 pages with 3 and 1 item
But i get - 3 pages and first page empty and others contains 2 items each:
page 1
1|333x216
page 2
2|398x430
page 3
3|406x445

last edited 10/09/17 by andrii burkatskyi
9 years ago

Ok, i think i understood what happens and i try to clarify my questions - there is a method to paginate a filtered collection?
Because pagination plugin continues to use page.collection() for pagination

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 53 10 hours ago
Support · by Anna, 3 days ago
2 60 13 hours ago
Support · by Justin Young, 14 hours ago
1 30 14 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 56 5 days ago