Octobercms - 在主题设置上从转发器组渲染字段

问题描述 投票:0回答:1

我尝试在我的主题设置yaml文件上使用转发器组。所以我将上面的代码添加到我的theme / config / fields.yaml:

fields:
    cont:
        tab: Content
        name: cont
        label: Content
        type: text
    content:
        tab: Content
        label: Content
        prompt: Add content block
        span: full
        type: repeater

        groups:
            textarea:
                name: Textarea
                description: Basic text field
                icon: icon-file-text-o
                fields:
                    text_area:
                        label: Text Content
                        type: textarea
                        size: large
            quote:
                name: Quote
                description: Quote item
                icon: icon-quote-right
                fields:
                    quote_position:
                        span: auto
                        label: Quote Position
                        type: radio
                        options:
                            left: Left
                            center: Center
                            right: Right
                    quote_content:
                        span: auto
                        label: Details
                        type: textarea

在主题设置后端一切正常,我可以在我的字段上插入数据。

现在我尝试在我的cms页面上渲染这些字段,但无论我尝试什么,我都没有成功。我尝试:

{% for fields in this.theme.content%}
     {{ fields.textarea }}
{% endfor %}

{% for fields in this.theme.contents %}
    {% if fields.groups == "textarea" %}
        {{fields.groups.textarea}}
    {% endif %}
{% endfor %}

但我不能渲染字段。

field repeater octobercms octobercms-backend
1个回答
2
投票

嗯,似乎有一些混乱和一些错误的变量名:)

让我们解决这个问题。

最终结果将是这样的:

{% for field in this.theme.content %}            
    {% if field._group == "textarea" %}
        <h1>{{field.text_area}}</h1>
    {% endif %}
    {% if field._group == "quote" %}
        <h1>{{field.quote_position}}</h1>
        <h1>{{field.quote_content}}</h1>
    {% endif %}     
{% endfor %}

什么是错误[如果你赶时间跳过这个:)](它在这里为你的改进它不服务任何其他目的:))

您正在使用contentso,您需要确保使用正确的变量名称,您可以使用this.theme.content而不是this.theme。>> contents <<

接下来它的field._group不是fields.groups

最后fields

fields:
  text_area:
  ....

所以你需要使用它们field.text_area而不是field.textareafield.quote_content等......

如果您发现任何困难请评论。

© www.soinside.com 2019 - 2024. All rights reserved.