1

I have a block that I want to show on the front page, but not on every paged page (i.e., don't show it on /front-page?page=1).

How can I achieve this?

1
  • 1
    This module will give you a bunch of extra conditions, one of them being to see if a URL parameter is or isn't set. Might be worth a try. Use at your own risk, it's very much a work in progress
    – Clive
    Dec 12, 2017 at 9:34

3 Answers 3

2

Install and enable request_data_conditions module

Then on the configuration of your block add following settings

  • Pages as <front>
  • URL query parameters set
    • page as must not be set
    • page as must equal 0
    • uncheck require all

enter image description here

3
  • Or page == 0 (can happen sometimes)
    – Clive
    Mar 12, 2019 at 10:10
  • @clive perhaps this is a better setup than ^
    – GiorgosK
    Mar 12, 2019 at 10:25
  • That's what I always go with, yeah :)
    – Clive
    Mar 12, 2019 at 10:35
0

Have you configured the block as shown in screen shot? enter image description here

If this block is generated using code, also have a look at code also.

3
  • Yes it is like in screen, but block is showing on <front>/?page.... to, but i want to display block ony on the first page of homepage
    – llSAntASll
    Dec 12, 2017 at 10:49
  • See in this module helps drupal.org/project/block_visibility_groups
    – Sharique
    Dec 12, 2017 at 13:11
  • i installed that module before asking this question ( module dident solved my problem
    – llSAntASll
    Dec 13, 2017 at 15:00
0

In hook_preprocess_page() add the following code.

if(!isset($_GET['page']))
$block_entity = Drupal\block_content\Entity\BlockContent::load(BLOCK_ID);// BLOCK_ID
$block_view = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block_entity, 'DISPLAY_VIEW_NAME');
if ($block_view) {
    $variables['page']['my_block'] = $block_view;
}
}

In your Twig template, print the block with the following code.

{% if page.my_block %}
  {{ page.my_block }}
{% endif %}

Refference: Render a custom block programmatically

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.