Trying to make pagination like this:
<div class="flex justify-between border-t border-grey-lighter py-6 mt-8">
<p>
@if($page->getPrevious() && ! $page->getPrevious()->exclude_pagenav)
<a href="{{ $page->getPrevious()->_meta->url }}/">
← {{ $page->getPrevious()->navigation['title'] ?? $page->getPrevious()->title }}
</a>
@endif
</p>
<p>
@if($page->getNext() && ! $page->getNext()->exclude_pagenav)
<a href="{{ $page->getNext()->_meta->url }}/">
{{ $page->getNext()->navigation['title'] ?? $page->getNext()->title }} →
</a>
@endif
</p>
</div>
And include it in documentation.blade.php
@section('nav-toggle')
@include('_nav.menu-toggle')
@endsection
@section('body')
<section class="container max-w-4xl mx-auto px-6 md:px-8 py-4">
<div class="flex flex-col lg:flex-row">
<nav id="js-nav-menu" class="nav-menu hidden lg:block">
@include('_nav.menu', ['items' => $page->navigation])
</nav>
<div class="w-full lg:w-3/5 break-words pb-16 lg:pl-4" v-pre>
@yield('content')
+ @include('_components.pagination')
</div>
</div>
</section>
@endsection
Always get an error during vendor/bin/jigsaw build or npm run watch
In PageVariable.php line 20:
No function named "getPrevious" was found in the file "config.php".
If add holders in config.php:
...
'getPrevious' => function () {
},
'getNext' => function () {
}
it works as expected and described in documentation.
Make sure you working within the context of a collection, as $page->getNext() and $page->getPrevious() are only available for paging through collection items; is documentation.blade.php being used to render a collection?
Of course. If I dump $page variable, it's instance of TightenCo\Jigsaw\Collection\CollectionItem, and it's works fine if I declare holders like this in config.php:
'getPrevious' => function () {
},
'getNext' => function () {
}
But without it, error appears during building process:
In PageVariable.php line 20:
No function named "getPrevious" was found in the file "config.php".
But in runtime get_class($page) returns TightenCo\Jigsaw\Collection\CollectionItem
As you can see in my previous message, I use standard documentation.blade.php template and just include @include('_components.pagination') below @yield('content').
The standard documentation template does not use collections. When I test your code, inspecting $page in _components/pagination.blade.php reveals that it's an instance of PageVariable rather than CollectionItem, as would be expected when not using collections.
Can you share a repo of your code with me, so I can take a more detailed look, and better suggest a solution?
Have created an example repo for you - Jigsaw Collections Pagination
It's based on docs template and just migrated default docs to workflow collection with pagination component. (See in 2nd commit)
vendor/bin/jigsaw buildvendor/bin/jigsaw build againThe issue seems to be the remaining original docs folder; pages in there are not collection items but extend the _layouts.documentation template, which includes the pagination partial. So $page->getNext() and $page->getPrevious() don't exist for those docs pages when they get rendered. Remove those docs, or have them extend a different template, and it will work as expected.
Incidentally, you might want to prefix your collections config folder with a _; the contents of that folder are getting rendered to build_local at the moment.
Thanks for help! Now it works as expected, I have removed an docs folder, it's unnecessary in my project, I have many collections of docs.
And thanks for advice, I will prefix collections folder.