"previous page" & "next page"

I am now starting to migrate my previous wiki sites to Grav (trying hard).

Clipboard01

In one of the “topics”, I may have over 20 “pages” (see above for a quick illustration, with 01/02…). I wish to place a link in each page (default.md in each folder) to link to “prev page” and “next page”.

Appreciate your help on this.

@taylorren, If you are still using an inherited theme based on Quark, the functionality is already available.

To implement ‘Next’ and ‘Previous’ on your pages, you need to do the following:

  • In page ‘09.gcti/default.md’, define a collection of pages.

    ---
    content:
       items: '@self.children'
    ---
    

    Every child-page can now use functions like page.nextSibling and page.isLast in templates. Template ‘/quark/templates/partials/blog-item.html.twig’ is an example using it.

  • Change the template for all the subpages, eg. ‘01.toc/default.md’, from ‘default.md’ to ‘item.md’.
    This will turn each page into a blog item page.

    Your folder structure should now look as follows:

    ./pages/
    ├── ...
    ├── 09.gcti
    │   ├── 01.toc
    │   │   └── item.md
    │   ├── 02.preface
    │   │   └── item.md
    │   ├── 03.other
    │   │   └── item.md
    │   └── default.md
    ├── ...
    
  • Done!

Bonus suggestion:
What you are trying to achieve very much looks likes a blog functionality. You might want to have a look at the ‘Blog Site’ skeleton which gives you an idea of how a blog using the Quark theme looks like.

NB. The above steps uses the build-in blog functionality of Quark. If you want ‘gcti’ to show a list of ‘items’, you should rename ‘09.gcti/default.md’ into ‘09.gcti/blog.md’

1 Like

Thanks and I will try.

And thanks for the bonus tip. Actually I am not writing a blog in this sense. I have a dedicated WordPress site solely for blog purpose.

I use wiki-type of framework to have a better navigation between pages with tight connections. For example, all pages in gcti will belong to, in this case, a book.

Just to add some more infos, if your are working on your own theme, there are many useful methods for the Page Collection Object listed in the docs.

Among which :

  • Collection::prevSibling($path)
  • Collection::nextSibling($path)
  • Collection::isFirst($path)
  • Collection::isLast($path)

Hi @taylorren, I do something similar in my Bootstrap4 Open Matter and Quark Open Publishing themes called “Sections” where based on a folder hierarchy next/prev page buttons are automatically generated. Support for a taxonomy tag called filter is also supported to dynamically generate different views of the pages.

You can see a live demo at:
https://demo.hibbittsdesign.org/grav-open-publishing-quark/multi-section-page

And here is it’s page structure:

And view it’s related Twig at:

Hope the above might be helpful.
Paul

1 Like

I have done it and tweaked a bit. Now it is working very fine. Thanks!

Thanks @paulhibbitts