php Drupal Twig主题建议

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Drupal Twig主题建议相关的知识,希望对你有一定的参考价值。

/**
 * Implements hook_theme_suggestions_taxonomy_term_alter() for mythemename.
 */
function mythemename_theme_suggestions_taxonomy_term_alter(array &$suggestions, array $variables, $hook) {

  if (\Drupal::currentUser()->isAuthenticated() && in_array($hook, ['taxonomy_term'])) {

    /** @var \Drupal\taxonomy\TermInterface $term */
    $term = $variables['elements']['#taxonomy_term'];
    $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
    $suggestions[] = 'taxonomy_term__' . $sanitized_view_mode;
    $suggestions[] = 'taxonomy_term__' . $term->bundle() . '__' . $sanitized_view_mode;
    $suggestions[] = 'taxonomy_term__' . strtolower($term->label()) . '__' . $sanitized_view_mode;
    $suggestions[] = 'taxonomy_term__' . $term->bundle() . '__' . strtolower($term->label());
    $suggestions[] = 'taxonomy_term__' . $term->bundle() . '__' . strtolower($term->label()) . '__' . $sanitized_view_mode;
    return $suggestions;
  }
}

以上是关于php Drupal Twig主题建议的主要内容,如果未能解决你的问题,请参考以下文章

块内主题化 Drupal 8

Drupal / Twig / Symfony Routing为base_url返回“null”

如何在drupal 8中的主题字段

主题为Drupal 7的Ubercart“/ cart”页面

Drupal 7模板(主题钩子)的建议

Drupal 8 在 Twig 模板中渲染内容