3

I'm creating a custom theme with base theme: stable. I have copied the template/layout/page.html.twig file into my theme. As I am reading the twig file I have noticed that there are some regions that I am not providing but are still being rendered.

Part of the file comment lists the regions available.

/*
 * Regions:
 * - page.header: Items for the header region.
 * - page.primary_menu: Items for the primary menu region.
 * - page.secondary_menu: Items for the secondary menu region.
 * - page.highlighted: Items for the highlighted content region.
 * - page.help: Dynamic help text, mostly for admin pages.
 * - page.content: The main content of the current page.
 * - page.sidebar_first: Items for the first sidebar.
 * - page.sidebar_second: Items for the second sidebar.
 * - page.footer: Items for the footer region.
 * - page.breadcrumb: Items for the breadcrumb region.
 */

I went looking in the stable.info.yml file and noticed there is not an entry for regions: so I am at a loss as how the page.html.twig file is able to render regions that are not listed in the stable.info.yml file.

Questions

  • How does this work without being defined in the stable.info.yml file.
  • Are there any other regions that work like this that are not in the page.html.twig file.
  • From what I recall, if no regions are specified in the theme, the core provides defaults itself. I could be wrong though. – Kevin Jan 20 '17 at 18:57
  • You are correct I just found documentation on it. – FatGuyLaughing Jan 20 '17 at 19:18
  • Okay, adding as an answer then. – Kevin Jan 20 '17 at 19:21
  • Sorry didn't realize you were responding with an answer down below. I went ahead and marked yours as the answer since you were the first to find it. Thanks again!! @Kevin – FatGuyLaughing Jan 20 '17 at 19:23
5

If no regions are specified in the theme, the core provides defaults itself.

From the docs page: https://www.drupal.org/docs/8/theming-drupal-8/adding-regions-to-a-theme

Default Regions:

page.header: Items for the header region.

page.primary_menu: Items for the primary menu region.

page.secondary_menu: Items for the secondary menu region.

page.highlighted: Items for the highlighted content region.

page.help: Dynamic help text, mostly for admin pages.

page.content: The main content of the current page.

page.sidebar_first: Items for the first sidebar.

page.sidebar_second: Items for the second sidebar.

page.footer: Items for the footer region.

page.breadcrumb: Items for the breadcrumb region.

If your theme does not declare any regions Drupal will assume this set of defaults. These regions correspond with what the default core/modules/system/templates/page.html.twig file expects, as well as two hidden regions, page_top, and page_bottom - you don't need to declare these final two if you override the defaults, however the {{ page_top }} and {{ page_bottom }} Twig variables should be retained in the html.html.twig template.

4

After some more research I finally found it here. The following is a quote of the section explaining how it works.

Default Regions

See the page.html.twig documentation for a list of default regions.

  1. page.header
  2. page.primary_menu
  3. page.secondary_menu
  4. page.highlighted
  5. page.help (dynamic help text, mostly for admin pages)
  6. page.content (main content of current page)
  7. page.sidebar_first
  8. page.sidebar_second
  9. page.footer
  10. page.breadcrumb

If your theme does not declare any regions Drupal will assume this set of defaults. These regions correspond with what the default core/modules/system/templates/page.html.twig file expects, as well as two hidden regions, page_top, and page_bottom - you don't need to declare these final two if you override the defaults, however the {{ page_top }} and {{ page_bottom }} Twig variables should be retained in the html.html.twig template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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