Hiding Page Title Block on Specified Pages in a Module

I am able to use the UI (http://farmos/admin/structure/block/manage/gin_page_title?destination=/admin/structure/block) to configure such that the page title does not appear on particular pages. But I would like that to be part of my module configuration.

I used the configuration synchronization to export the necessary configuration. Drupal said this had the filename: block.block.gin_page_title.yml. I saved the content of that in my module as config/block.block.farm_fd2_gin_page_title.yml`. Then uninstalled and reinstalled the module.

But no luck. The page header still appears on the pages that I was trying to exclude it from. Note: I also tried placing the file in (config/install which also did not work).

I think this may really be more of a Drupal question, but thought I’d try here hoping that I’m just missing something obvious and someone can suggest a quick fix.

Here is the content of the block.block.farm_fd2_gin_page_title.yml if it helps:

langcode: en
status: true
dependencies:
  module:
    - system
  theme:
    - gin
_core:
  default_config_hash: HLQY2xgby8K3vN_98hiOSasOhm9pdCsH234-s0duJ8Q
id: gin_page_title
theme: gin
region: header
weight: -30
provider: null
plugin: page_title_block
settings:
  id: page_title_block
  label: 'Page title'
  label_display: '0'
  provider: core
visibility:
  request_path:
    id: request_path
    negate: true
    pages: '/fd2/*'
1 Like

Hmm one way to accomplish this is with a simple CSS file that your module adds to those pages. If you want to hide the whole header I think this CSS rule would work:

header {
  display: none;
}

You can put that in a file called css/mycss.css inside your module, and then add a mymodule.libraries.yml file to “wrap” it in a “library” (https://www.drupal.org/docs/develop/creating-modules/adding-assets-css-js-to-a-drupal-module-via-librariesyml):

mycss:
  css:
    theme:
      css/mycss.css: { }

Then you can “attach” that library to the pages you want. If you are building those pages as a controller, you can attach it via the $build array that your controller creates:

$build['#attached']['library'][] = 'mymodule/mycss';

Rename mymodule and mycss to whatever you want.

Hope that helps!

Thanks for the suggestion.

I’m really only looking to hide the page title that appears in bold at the top of the each page (e.g. Locations, Dashboard, People but not on those pages, only on my pages.) I would like to keep all of the other farmOS header content (menus, breadcrumbs, etc). But I think this approach should work,

Works like a charm! Thanks!

1 Like

In case it’s ever helpful… I ended up using:

#block-gin-page-title {
  display: none;
}

as header also happened to match something in one of the components I was using and both were hidden.

Also, since I’m working with Vue.js single file components, I just included the css in the component in each component that wants to hide the page header rather than in the module.

2 Likes