Block regions in Drupal 8 & AdaptiveTheme

Adding block regions in Drupal 8 using AdaptiveTheme
Juli, 2016
Larry Elektrisch

Agreed, learning a new programming language or framework takes time and sometimes tends to be a real drag. But still, knowing this does not really help much when it takes hours to do a task, that you'd do within minutes in a well known environment and you already start hating this new framework.

It just took me about two hours to add a new block region in Drupal 8 using AdaptiveTheme and I'd like to share what I learned ...

How to add a new block region in Drupal 8 using AdaptiveTheme

Following the default approach of adding the region in the and page.html.twig, you'll quickly realize, that your changes are overwritten, when fiddling with your theme's settings in the Drupal backend. 

What you want to do instead is navigating to your ./public_html/themes/YOUR_ADAPTIVETHEME_SUBTHEME/layout/site-builder/ directory and edit the site-builder.markup.yml file.

Let's say you want to add a new block region below the Main content region, that exists by default in a Subtheme created with AdaptiveTheme's Theme Generator. 

Open the above mentioned site-builder.markup.yml file and find the main region, which should look like this:

      id: main-content
        label: 'Main content'
        order: 1
        label: 'Sidebar first'
        order: 2
        label: 'Sidebar second'
        order: 3

Just below this region, add a few newlines and add the code for your new region:

      id: new-block-region
        label: 'My new block region'
        order: 1

Double and triple check you got all indentations right and save the file. Done that, once again check if you got all indentations right or your block region just won't show up properly. If you do something wrong, it might show up on the Blocklayout page, but not on the page.

Then navigate to the appearance settings page of your theme, eg. admin/appearance/settings/your_themename, expand the Layout Section on that page and click the Save layout settings button. This will create a new template in templates/generated/page.html.twig as well as a new file.

After that, your new region should show up on the Blocklayout page. If it doesn't, just rebuild the cache (drush cache-rebuild).

Actually, pretty simple, if you know where to look ;)