By chenyi, 7 August, 2024

{#
/**
 * @file
 * Theme override for the basic structure of a single Drupal page.
 *
 * Variables:
 * - logged_in: A flag indicating if user is logged in.
 * - root_path: The root path of the current page (e.g., node, admin, user).
 * - node_type: The content type for the current node, if the page is a node.
 * - head_title: List of text elements that make up the head_title variable.
 *    May contain one or more of the following:
 *    - title: The title of the page.
 *    - name: The name of the site.
 *    - slogan: The slogan of the site.
 * - page_top: Initial rendered markup. This should be printed before 'page'.
 * - page: The rendered page markup.
 * - page_bottom: Closing rendered markup. This variable should be printed after
 *    'page'.
 * - db_offline: A flag indicating if the database is offline.
 * - placeholder_token: The token for generating head, css, js and js-bottom
 *    placeholders.
 *
 * @see template_preprocess_html()
 */
#}

<!DOCTYPE html>

<html{{ html_attributes }}>
  <head>

<head-placeholder token="{{ placeholder_token|raw }}">
<title>{{ head_title|safe_join(' | ') }}</title>

<css-placeholder token="{{ placeholder_token|raw }}">
<js-placeholder token="{{ placeholder_token|raw }}">

      </head>

      <body{{ attributes }}>

{#
  Keyboard navigation/accessibility link to main content section in
  page.html.twig.
#}

<a href="#main-content" class="visually-hidden focusable">

{{ 'Skip to main content'|t }}

</a>

{{ page_top }}

{{ page }}

{{ page_bottom }}

<js-bottom-placeholder token="{{ placeholder_token|raw }}">

      </body>

</html>

 

在这个模板中输出了DOCTYPEhtmlheadbody标签,这些是htm页面所不可缺少的东西。然后还有一些变量,比如用于输出标题、cssjs的变量,用于输出页面模板的变量page。这里的js,会根据库中的声明来判断应该将文件放在页面的顶部head标签中,还是放在页面的底部。

 

{{ page }}

这条语句用于输出嵌套在html模板中的page模板。

 

{{ page_top }}

{{ page_bottom }}

用于输出页面上方和下方附加的区域,比如我们之前提到过的管理员登录之后,在页面顶部显示的管理菜单就是从这里的page top输出的。而page模板(page.html.twig),则用来输出body标签中的全部内容。