0

I have a view-page with a pager of about 10 pager-pages.

This view also has a a view-header. The text of this header repeats itself in all pager-pages of that view, which is a bit funny because in page 2 or even in page 10 the user could read the same header text "welcome to my blog".

How to make a header of a view page to appear only in the view's first page?

1
  • I rolled back the edit because this is solely about a header of a view. Other headers are just not relevant.
    – ali
    Nov 19, 2023 at 22:00

2 Answers 2

1

You can use hook_preprocess_views_view__HOOK() hook (in .module/theme file) for display header conditionally:

function Mymodulename_preprocess_views_view__machine_name_of_view(&$vars) {
  $view = $vars['view'];
  $pager_number = $view->pager->current_page;
  // current page key value start from 0 
  // Added condition header should display only for first page
  if($pager_number != 0){
     unset($vars['header']);
  }
}  
0

Install the Filter Twig module:

composer require 'drupal/filter_twig:^2.2'
drush en filter_twig

Visit /admin/config/content/formats/add, enter the name "Views Twig", check "Replaces Twig value" and save.

In the View add a Header: Global: Text area, select the text format Views Twig and fill in the text:

{% if [view:current-page] == 1 %}
  Page 1
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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