如何在主题安装中将块分配给特定区域?


9

Drupal 8默认提供一些块。例如。Site BrandingMain NavigationPowered by DrupalSearch等。

我创建了一个具有Site brandingMain Navigation命名区域的主题,可以在其中放置相应的块。

启用主题时,默认情况下,Site BrandingMain Navigation块分别放置在主题的HeaderFirst Sidebar区域中。

默认情况下,如何在主题安装中放置Site BrandingMain Navigation阻止到它们各自的区域?


2
您必须创建作为配置对象的块实例,并将其放入主题的config / install目录中。

Answers:


8

首先,您应该手动更改每个所需的块区域Administration>Structure>Block layout Tab,然后转到以下位置的配置导出功能:
Administration>Configuration>Development>Configuration synchronization>Export Tab>Single item导出主题的每个块设置。
然后,您应该查看生成的YAML文件,并将其放在主题中的新文件夹中/config/install。然后,您卸载了主题,然后将其作为默认主题重新安装。

摘要:
1.安装MY_THEME
2.将块放置在所需的区域中
3.导出配置文件并从中删除,并删除 示例块文件的uuid核心配置哈希
Site Brandingblock.block.MY_THEME_branding.yml

langcode: en
status: true
dependencies:
  module:
    - system
  theme:
    - DEPENDENT_THEME
id: MY_THEME_branding
theme: MY_THEME
region: site_branding
weight: 0
provider: null
plugin: system_branding_block
settings:
  id: system_branding_block
  label: 'Site branding'
  provider: system
  label_display: '0'
  use_site_logo: true
  use_site_name: true
  use_site_slogan: true
visibility: {  }
  1. 将配置文件放置到MY_THEME/config/optionalMY_THEME/config/install目录中(如果您完全确定满足所有依赖性)
  2. 卸载MY_THEME并清除所有缓存
  3. 重新安装MY_THEME一次

7

找到了答案:

这可以通过为theme/config/install文件夹中的每个块添加yml文件(块实例)来完成。

例如,要将Site Branding块(机器名称system_branding_block)分配给Site Branding区域(机器名称site_branding),请在config/install/block.block.THEME_NAME_branding.yml文件中添加以下代码:

langcode: en
status: true
dependencies:
  module:
    - system
  theme:
    - DEPENDENT_THEME
id: THEME_NAME_branding
theme: THEME_NAME
region: site_branding
weight: 0
provider: null
plugin: system_branding_block
settings:
  id: system_branding_block
  label: 'Site branding'
  provider: system
  label_display: '0'
  use_site_logo: true
  use_site_name: true
  use_site_slogan: true
visibility: {  }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.