DEV Community

oskar calvo
oskar calvo

Posted on

Add custom twig templates to drupal regions

page.hmtl.twig

{#
/**
 * @file
 * Tara is theme implementation to display a single page.
 *
 * The doctype, html, head and body tags are not in this template. Instead they
 * can be found in the html.html.twig template.
 *
 * Available variables:
 *
 * General utility variables:
 * - base_path: The base URL path of the Drupal installation. Will usually be
 *   "/" unless you have installed Drupal in a sub-directory.
 * - is_front: A flag indicating if the current page is the front page.
 * - logged_in: A flag indicating if the user is registered and signed in.
 * - is_admin: A flag indicating if the user has permission to access
 *   administration pages.
 *
 * Site identity:
 * - front_page: The URL of the front page. Use this instead of base_path when
 *   linking to the front page. This includes the language domain or prefix.
 *
 * Page content (in order of occurrence in the default page.html.twig):
 * - node: Fully loaded node, if there is an automatically-loaded node
 *   associated with the page and the node ID is the second argument in the
 *   page is path (e.g. node/12345 and node/12345/revisions, but not
 *   comment/reply/12345).
 *
 * Regions:
 * - page.header_top: Items for the header top region.
 * - page.site_branding: Items (logo / site name / site slogan) for the site branding region.
 * - page.primary_menu: Items for the primary menu region.
 * - page.search_box: Items for the full page search region.
 * - page.breadcrumb: Items for the breadcrumb region.
 * - page.highlighted: Items for the highlighted region.
 * - page.content: The main content of the current page.
 * - page.content_top: Items for the content top region.
 * - page.content_bottom: Items for the content bottom region.
 * - page.sidebar_first: Items for the first / left sidebar.
 * - page.sidebar_second: Items for the second / right sidebar.
 * - page.footer_top: Items for the footer top region.
 * - page.footer_first: Items for the first footer column.
 * - page.footer_second: Items for the second footer column.
 * - page.footer_third: Items for the third footer column.
 * - page.footer_fourth: Items for the fourth footer column.
 * - page.footer_bottom: Items for the footer bottom region.
 *
 * @see template_preprocess_page()
 * @see html.html.twig
 */
#}
{% include '@tara/template-parts/header.html.twig' %}
{% include '@tara/template-parts/breadcrumb_region.html.twig' %}
{% include '@tara/template-parts/highlighted.html.twig' %}
<div id="main-wrapper" class="main-wrapper">
  <div class="container">
  <div class="main-container">
    <main id="main" class="page-content">
      <a id="main-content" tabindex="-1"></a>{# link is in html.html.twig #}
      {% include '@tara/template-parts/content_top.html.twig' %}
      {{ page.content }}
      {% include '@tara/template-parts/content_bottom.html.twig' %}
    </main>
    {% include '@tara/template-parts/left_sidebar.html.twig' %}
    {% include '@tara/template-parts/right_sidebar.html.twig' %}
  </div> {# /.main-container #}
  </div> {# /.container #}
</div>{# /main-wrapper #}
{% include '@tara/template-parts/footer.html.twig' %}
Enter fullscreen mode Exit fullscreen mode

header-top-content.html.twig.twig

<div class="header-top">
  <div class="container">
    <div class="header-top-container">
      {% if page.header_top %}
        <div class="header-top-left header-top-block">
          {% include '@tara/partials/header-top-content.html.twig' with { content: page.header_top } %}
        </div> <!--/.header-top-left -->
      {% endif %}
      {% if all_icons_show %}
        <div class="header-top-right header-top-block">
          {% include '@tara/template-parts/social-icons.html.twig' %}
        </div> <!--/.header-top-right -->
      {% endif %}
    </div> <!--/.header-top-container -->
  </div> <!--/.container -->
</div> <!--/.header-top -->
Enter fullscreen mode Exit fullscreen mode

header-top-content.html.twig

{# themes/custom/tara/templates/partials/header-top-content.html.twig #}
<div class="custom-header-top-content">
  {{ content }}
</div>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)