Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Commit

Permalink
make pagination work (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed May 12, 2021
1 parent a3791ad commit 2a9fd83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ Use the same params as the `{{ collection }}` tag
@endcollection
```

#### Collection Pagination
@collection('the_collection', ['limit' => 2, 'paginate' => true])
@foreach($entry['entries'] as $entry)
@data($entry)
Title: {{ $title }}
@enddata
@endforeach
@endcollection

### Data

Use this when you have Statamic data but it's a `Value` object. This will return a keyed array with all the fields as string/ints/arrays (recursively).
Expand Down
6 changes: 5 additions & 1 deletion src/Directives/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public function handle(string $handle, array $params = [])
array_merge(['from' => $handle], $params)
);

if ($entries->isEmpty()) {
if (collect($entries)->isEmpty()) {
return [['no_results' => true]];
}

if (in_array('paginate', $params)) {
return [$this->getAugmentedValue($entries)];
}

return $this->getAugmentedValue($entries);
}
}

0 comments on commit 2a9fd83

Please sign in to comment.