0

For a project running on Drupal 9.2.9, I want pagers on the top and bottom of view pages. I have it working on pages by an edit to a custom views-view.html.twig in the theme (using the full pager option in the Views display). Unfortunately, this resulted in double pagers on blocks using minipager also.

I think I need a little conditional logic in the views-view.html.twig template to check for if … is full pager versus if … is mini pager, or if … is page vs. if … is block. How can I achieve that?

Maybe, a better approach is a template for full pager and a different one for mini pager, but I don't understand how all these templates work together to use that approach.

3

Views provides theme suggestions, one of them keys off of the display type (e.g. page, block, etc.). Override the suggestion for pages (views-view--page.html.twig) and copy {% if pager %}{{ pager }}{% endif %} to wherever you want on top of the view. This will only apply to Page displays of a view, and nowhere else.

Refer to views-view.html.twig for the default markup of this template. The default placement of {{ pager }} is after the rows.

3

See Views template files for details on how views templates can be overridden. To quote from that page:

All views templates can be overridden with a variety of names, using the view, the display ID of the view, the display type of the view, or some combination thereof.

So in your case, you probably want to have different templates for your views block and your views page.

These links could also help you better understand how template suggestions work, especially in the context of views:

Also Locating Template Files with Debugging can help you to enable twig debug and get information on the available template suggestions in your specific case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.