Ad

Octobercms - Render Fields From Repeater Groups On Theme Settings

I try to use repeater groups on my theme settings yaml file. So i add the above code to my 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

Everything is working fine on theme settings backend and i can insert data on my fields.

Now i try to render those fields on my cms page but no mater what i try i never succeed. I try:

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

also

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

But i can't render fields.

Ad

Answer

Hmm, it seems some confusion there and some wrong variable names :)

let's fix this.

End result would be like this :

{% 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 %}

what are the mistakes [ If you are in hurry skip this :) ] (its here for your improvement it does not server any other purpose :) )

You are using contentso you need to make sure you use correct variable name here you can use this.theme.contentnot the this.theme.>>contents<<

next its field._groupnot thefields.groups

and finallyfields its

fields:
  text_area:
  ....

so you need to use them field.text_areanot thefield.textarea and field.quote_content so on ...

if you find any difficulties please comment.

Ad
source: stackoverflow.com
Ad