getgrav / grav-plugin-pagination

Grav Pagination Plugin
https://getgrav.org
MIT License
27 stars 20 forks source link

feature request: ignore url params #14

Closed gigago closed 8 years ago

gigago commented 8 years ago

By default, the pagination plugin copies any and all url parameters when creating the pagination links. Sometimes, this behaviour is undesirable, specifically when a copied parameter conflicts logically with the presented page's contents. Take for example, a paginated list of unique items with a 'selected item' view, which should at all times match the selection in the visible slice of the list. The selected item may initially be indicated by an url parameter or it may be some default, like the first item on a given list page. However, it can never be present on more than one page. In this case, passing on the parameter via pagination links makes no sense and requires elaborate workarounds to prevent things from breaking. The cleanest solution is to optionally disable the reuse of url parameters by pagination. The following is a rudimentary site-wide implementation.

Note: this does not alter the pagination 'page' parameter itself which, as before, is appended to the base url after pagination.

blueprints

    ignore_url_params:
      type: toggle
      label: Ignore url params
      highlight: 1
      default: 0
      help: Enable this when pagination should ignore url params
      options:
        1: Enabled
        0: Disabled
      validate:
        type: bool

pagination.yaml

ignore_url_params: true

paginationhelper.php

    $url_params = ($config->get('plugins.pagination.ignore_url_params'))?
        ([]):(explode('/', ltrim($uri->params(), '/')));