简体   繁体   中英

How to add a block within twig template in Drupal 8

Does anybody know how to add a search block into main-menu block via twig template in Drupal8? enter image description here

I need something like that in main-menu.html.twig:

    <div class="wrapper">
        <div class="col-md-9"> menu ....</div>
        <div class="col-md-3"> Search block should be added there</div>
    </div>

Thanks a lot!!!

I've found a solution! We can add a new region in themename.info.yml , like that:

regions:
  navigation: 'Navigation'
  navigation_collapsible: 'Navigation (Collapsible)'
  header: 'Top Bar'
  blog_menu: 'Blog menu'
  highlighted: 'Highlighted'
  help: 'Help'
  content: 'Content'
  sidebar_first: 'Primary'
  sidebar_second: 'Secondary'
  footer: 'Footer'
  page_top: 'Page top'
  page_bottom: 'Page bottom'

And then call this wrapping this region in page.html.twig as needed.

<div class="wrapper">
    {{ page.blog_menu }}
</div>

So, both blocks (menu and search) will be added inside new region via admin and wrapped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM