具有木材和 ACF 灵活内容的古腾堡积木

Gutenberg Blocks with Timber and ACF Flexible Content

我们正在根据以下内容创建 block.twig 模板: https://timber.github.io/docs/guides/gutenberg/#how-to-use-acf-blocks-with-timber 使用 ACF 灵活的内容字段类型来创建古腾堡块。

作为参考,以下示例代码适用于转发器字段类型:

{% for field in fields.repeater %}
    Title: {{ field.title }} <br/>
    Url: {{ field.url }}
{% endfor %}

我们测试过,似乎工作正常。

使用灵活内容字段相当于什么?

谢谢。

@Rafael 它们有点复杂,只需要像处理数组一样处理它们。让我们假设您的灵活内容字段在其中被称为 my_fc_field。您创建了 2 个布局,每个布局都有一个文本字段,一个名为 tf_one,另一个名为 fc_two

{% for subfield in fields.my_fc_field %}
    Layout name: {{ subfield.acf_fc_layout }}
    Text Field Value: {{ subfield.tf_one ? subfield.tf_one : subfield.tf_two }}
{% endfor %}

做一个 {{ dump(fields.my_fc_field) }} 应该清楚里面有什么你可以 manipulate/output