如何在页面--front.html.twig中显示自定义字段内容类型到模板页面?

How to display custom field content type to template page in page--front.html.twig?

我是 Drupal 的新手,目前正在学习 Drupal 8。我想创建 HTML 到 Drupal 的动态转换。

为此,我创建了页面--front.html.twig 并从后端动态创建页面 "Home Page" 作为首页。因此它将自动 select 页面--front.html.twig 模板。 (这里我已经将内容类型添加为带有自定义字段的主页)

此处用于 HTML 到 drupal 的第一次转换 我在页面中放入的所有 HTML 代码--front.html.twig 及其相关的 css 和 Js。所以它会显示静态内容。

现在我想动态获取所有栏目内容。因此,我为该内容类型创建了其他字段,并在其中添加了一些内容,但现在我无法使用 {{ content.field_test_field }}

在模板首页中获取该自定义字段值

我用过下面的代码,

{{ dump(content|keys) }}
{{ content.field_third_section_content.0 }}
{{ fields.field_third_section_content.content }}
{{ node.body.value|raw }}
{{ content.field_third_section_content }}
{{ node.field_third_section_content.0.value }}
{{ node.teaser.value }}

{{ dump(content|keys) }} for this I got array(0) { }

,请给我一些简单的解释,这样可以更了解它的语法和功能。 &以上所有代码都不适合我。

请帮我解决这个问题。

提前致谢。

您可以使用以下输出类型显示页面--front.html.twig 的字段:

记得用您的字段名称替换 FIELDNAME。

输出块: {{ page.REGIONNAME }}

输出页面标题: {{ node.title.value }}

输出分类术语或下拉列表Select选项: {{ node.field_FIELDNAME.0.entity.label }}

输出通用文本字段: {{ node.field_FIELDNAME.value }}

正在输出图像或文件: {{ file_url(node.field_FIELDNAME.entity.fileuri')) }}

除非启用调试,否则 dump() 函数不会显示任何输出。
https://www.drupal.org/node/1903374