Jigsaw: No function named "getPrevious" was found in the file "config.php"

Created on 20 Mar 2019  路  6Comments  路  Source: tighten/jigsaw

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 }}/">
                &larr; {{ $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 }} &rarr;
            </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.

All 6 comments

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)

  1. Install it
  2. Try to run vendor/bin/jigsaw build
  3. See errors
  4. Try to uncomment these lines - https://github.com/slavarazum/jigsaw-collections-pagination/blob/master/config.php#L33-L34
  5. Run vendor/bin/jigsaw build again
  6. See a result with no errors and working pagination

The 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

minthemiddle picture minthemiddle  路  6Comments

cossssmin picture cossssmin  路  12Comments

nathangross picture nathangross  路  3Comments

mattstauffer picture mattstauffer  路  3Comments

Log1x picture Log1x  路  8Comments