我用嵌套块创建了一个自定义块。如何访问内部块中的字段?例如,我要显示图标,标题和描述。
我已经尝试了几种方法:
{% for block in value %}
{% if block.block_type == 'features' %}
{% for subblock in block.value %}
{{ subblock.value.title }}
这是我的块定义:
class Features_1_Block(blocks.StructBlock):
title = blocks.CharBlock()
description = blocks.TextBlock(required=False)
features = blocks.ListBlock(
blocks.StructBlock([
('icon', blocks.CharBlock()),
('title', blocks.CharBlock()),
('description', blocks.TextBlock())
])
)
class Meta:
template = 'streamfield_blocks/features_1.html'
当前没有输出。
答案 0 :(得分:2)
弄清楚了我的问题,这很尴尬。
{% for block in value.features %}
{{ block.title }}
{% endfor %}