【问题标题】:Where do PHP file corresponding to a twig files are stored in drupal 8与树枝文件对应的PHP文件存储在drupal 8中的位置
【发布时间】:2018-02-05 11:32:47
【问题描述】:

这是 page.html.twig 文件的一部分

<div class="content col-lg-{{ page.main_content_width }} col-md-{{ page.main_content_width }} col-sm-12 col-xs-12">
      {{ page.highlighted }}

      {{ title_prefix }}
      {% if title %}
        <h1>{{ title }}</h1>
      {% endif %}
      {{ title_suffix }}

      {{ tabs }}

      {% if action_links %}
        <nav class="action-links">{{ action_links }}</nav>
      {% endif %}

      {{ page.content }}


      {{ feed_icons }}
</div>

主题中没有名为highlighted的块区域。 这些变量存储在哪里。我找不到这个树枝文件的 php 模板文件

【问题讨论】:

  • 这个树枝中也没有块区域。它只显示highlighted 变量内容。
  • 区域在您的 THEME.info.yml 文件中定义,如果这是您所要求的。
  • 他在询问变量在哪里设置并传递给twig。其中PHP文件准确
  • @DarkBee 完全正确

标签: php drupal twig drupal-8


【解决方案1】:

这些变量是使用可渲染数组生成的,您始终可以在相应的预处理挂钩中更改/查看它们。在您的情况下,hook_preprocess_page 将向您显示树枝中使用的所有变量。

为了回答您在哪里设置这些值,/core/includes/theme.inc function template_preprocess_page 文件中正在准备这些变量。

function template_preprocess_page(&$variables) {
  $language_interface = \Drupal::languageManager()
    ->getCurrentLanguage();
  foreach (\Drupal::theme()
    ->getActiveTheme()
    ->getRegions() as $region) {
    if (!isset($variables['page'][$region])) {
      $variables['page'][$region] = array();
    }
  }
  $variables['base_path'] = base_path();
  $variables['front_page'] = \Drupal::url('<front>');
  $variables['language'] = $language_interface;

  // An exception might be thrown.
  try {
    $variables['is_front'] = \Drupal::service('path.matcher')
      ->isFrontPage();
  } catch (Exception $e) {

    // If the database is not yet available, set default values for these
    // variables.
    $variables['is_front'] = FALSE;
    $variables['db_is_active'] = FALSE;
  }
  if ($node = \Drupal::routeMatch()
    ->getParameter('node')) {
    $variables['node'] = $node;
  }
}

【讨论】:

    猜你喜欢
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多