Is there a way to limit where a block displays based on a query in the URL?


You can implement a condition plugin that does just that and then configure your block to use that condition, we did something similar once:

 * Condition on the page query param.
 * @Condition(
 *   id = "yourproject__first_page",
 *   label = @Translation("First page (by url query param)")
 * )
class FirstPage extends ConditionPluginBase {

   * {@inheritdoc}
  public function evaluate() {
    $match = !\Drupal::request()->query->get('page');
    return $this->configuration['negate'] ? !$match : $match;

   * {@inheritdoc}
  public function summary() {
    return $this->t($this->configuration['negate'] ? 'The %param parameter is not %value' : 'The %param parameter is %value or empty', ['%param' => 'page', '%value' => 0]);

Tags: Drupal 8 / Blocks

Similar questions

changing my ip based url to name based url
basically i have my website under 91.xx.xx.76/mywebsite in folder /var/www/mywebsite and i want the user to type, i have search some methods in doing so but doesn't actually solve it. they say to create a file under sites-available then enabled it i have created file under sites-available and also enabled it using a2ensite mywebsi...
How to programmatically create a View on a node that displays SQL Query content?
How can I programmtically create a View on node(s) that displays the content from a specific query? For example I would like to display the following: Essentially, I would like to grab the 'nid' from the current node and I would like the View to display all 'users' associated with the current node, as the query would return. I have been able to ach...
How can I implement paging for a custom query plugin which displays data from an external API?
Hi I have a requirement to display the data from external api but should not be imported into any entities. What I did is I have written a custom view query plugin which displays the data from external api. What I did is I have used the GuzzleHttp Client to get the data. Here is how my service looks like I called the service into my plugin query an...
How to limit access to content for which the Content Access module doesn't limit access?
I run a small business, and have created a website in Drupal 8 (should have used 7, bit late now, oooops). Part of the website is designed to be behind a subscription, which I've got working and works well. Only problem is, the content types I want to only be visible to people who have paid, are visible to everyone. I installed the Content Access m...
Is there a way to force some block caching despite system block caching option is disabled?
In /admin/config/development/performance settings page, my "cache blocks" options is disabled due to "Block caching is inactive because you have enabled modules defining content access restrictions." But I absolutely need to globally cache some blocks (in particular some superfish blocks because they recreates menu items on every page load if not c...
Is there any way to force a custom block in the Custom Block Library to invalidate cache on edit update?
I have created custom blocks in the Custom Block Library and placed instances of the blocks on a page in Block Layout. The blocks get cached for anonymous users. Editing the custom block and saving does not invalidate the cache for those instances of the blocks. Looking in the "cache_render" table I see that caches for blocks get created through th...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.