Wagtail块中的参数集未出现在管理UI中。

huangapple go评论55阅读模式
英文:

Parameter set in Wagtail block not appearing in admin UI

问题

我创建了一个自定义块类,它继承自Wagtail的URL块。在这个类中初始化URL块时,我设置了help_text参数。自定义块显示正常,除了帮助文本不显示之外。当块加载时,在UI中找不到它,并且悬停在块上也不显示帮助文本。文档中提到了URL块可以使用help_text参数。帮助文本应该显示在哪里,我如何让它显示在我的自定义块中?

我正在使用Wagtail版本4.1.1

自定义块的代码片段:

class AirtableBlock(URLBlock):
    url = URLBlock(icon="link", help_text="Lorem ipsum dolor sit amet, consectetur adipiscing elit")

    class Meta:
        template = "core/blocks/airtable_embed.html"
        icon = "code"

截图:
在管理UI中的自定义块

我已经尝试将help_text参数添加到URL块中。我期望看到文本添加到UI中,但它没有出现。

英文:

I created a custom block class that inherits from Wagtail's URL Block. When initializing the URL Block within this class, I set the help_text parameter. The custom block displays correctly, aside from the fact that the help text doesn't show. It's not present in the UI when the block loads, and hovering over the block doesn't show the help text either. The documentation notes that this help_text parameter is available for URL Blocks. Where should the help text be, and how can I get it to show in my custom block?

I'm using Wagtail version 4.1.1

Code snippet of the custom block:

class AirtableBlock(URLBlock):
    url = URLBlock(icon="link", help_text="Lorem ipsum dolor sit amet, consectetur adipiscing elit")

    class Meta:
        template = "core/blocks/airtable_embed.html"
        icon = "code"

Screenshot:
Custom block in admin UI

I've tried adding the help_text parameter to the URL Block. I expect to see the text added to the UI, but it doesn't appear.

答案1

得分: 0

要构建自定义块,您需要继承StructBlock。
帮助文本将由表单渲染处理:

class AirtableBlock(StructBlock):
    url = URLBlock(icon="link", help_text="URL帮助文本")

    class Meta:
        template = "core/blocks/airtable_embed.html"
        icon = "code"

然后在您的StreamField中:

content = StreamField(
    [
        ...,
        ("url", AirtableBlock(help_text="块级帮助")),
    ],
)

这将呈现为:

Wagtail块中的参数集未出现在管理UI中。

英文:

For constructing custom blocks, you need to inherit StructBlock.
https://docs.wagtail.org/en/stable/advanced_topics/customisation/streamfield_blocks.html

The form rendering will take care of the help text then:

class AirtableBlock(StructBlock):
    url = URLBlock(icon="link", help_text="url help")

    class Meta:
        template = "core/blocks/airtable_embed.html"
        icon = "code"

Then in your StreamField:

    content = StreamField(
        [
            ...,
            ("url", AirtableBlock(help_text="Block level help"))
        ],

This will render with:

Wagtail块中的参数集未出现在管理UI中。

huangapple
  • 本文由 发表于 2023年6月2日 09:17:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386594.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定