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.

Plugins

Paginate flex collection

plugins

Solved by pamtbaau View solution

Started by p 3 years ago · 4 replies · 546 views
3 years ago

I have updated the guestbook plugin to a recent plugin skeleton using flex-objects, see https://github.com/pikim/grav-plugin-guestbook. Now I'd like to be able to paginate the stored messages in twig using the standard pagination plugin. Is this possible?

If I do

TWIG
{% set collection = grav.get('flex').collection('guestbook') %}
{% do paginate(collection, 3) %}

I get the error that the types of argument 1 don't match:

TXT
Argument 1 passed to Grav\Plugin\Pagination\PaginationHelper::__construct() must be an instance of Grav\Common\Page\Collection, instance of Grav\Common\Flex\Types\Generic\GenericIndex given

The manual says that flex collections can be paginated with the slice filter. But this way I would have to write all the business logic behind that, wouldn't I?

3 years ago Solution

@pikim, As you may have experienced, I don't think that Page collections and Flex collections share the same interface.

At first glance, I'm afraid an extension of plugin Pagination is required, or an entire new FlexPagination plugin needs to be created.

3 years ago

@pamtbaau
Thanks. I'll take a look at the pagination plugin.

Do you know how I can add flex layout files to plugins? I tried to copy them to user/plugins/guestbook/templates/flex/guestbook/collection/default.html.twig and user/plugins/guestbook/templates/flex/guestbook/object/default.html.twig, but that doesn't work. I get a ERROR: Layout 'default' for flex collection 'guestbook' was not found. error on the displayed page with URL /directory:guestbook. When I copy them to the according flex-objects plugin directory, it works.

3 years ago

@pikim,

Do you know how...

I have no idea. I'm not a flex user and I simply read/write form entries from/into a yaml file. Old school perhaps, but so far I haven't found a compelling use-case to invest time in it. It feels too complex to my liking.

👍 1
3 years ago

@pamtbaau

Maybe it is oldschool, but that's ok when it works. I think I'll go with the current version as It's ok for me for now.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 72 2 months ago