【发布时间】:2017-03-21 09:51:36
【问题描述】:
我是 Drupal 8 的新手,遇到一个问题。
我需要在我的主题页面 page-front.html.twig 中显示一个 CCK 字段(自定义字段)。
据我所知,在非节点页面中显示节点变量是不可能的,所以我开始做一个预处理钩子。
我的预处理如下所示:
mythemename.theme
<?php
function THEME_NAME_preprocess_page(&$vars) {
if (isset($vars['node'])) {
$node = $vars['node'];
if ($node->isset('field_numero_cin') {
$field_cin = $node->get('field_numero_cin');
$vars['field_cin'] = $field_image->value();
}
}
}
不幸的是,当我调试(kint)时,page-front.html.twig 中的变量是 NULL。
【问题讨论】:
-
我也不太喜欢我。但是,我不想重复这个问题。我也面临同样的问题。你修好了这个?
标签: twig drupal-8 preprocessor