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.
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 content
so you need to make sure you use correct variable name here you can use this.theme.content
not the this.theme.>>contents<<
next its field._group
not thefields.groups
and finallyfields
its
fields:
text_area:
....
so you need to use them field.text_area
not thefield.textarea
and field.quote_content
so on ...
if you find any difficulties please comment.
Related Questions
- → October CMS create a multi select Form field
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
- → I can't convert Json to string [OctoberCms]
- → How to dynamically add class to parent div of focused input field?
- → Knockout JS - How to return empty strings for observable fields
- → Upload file with iron-ajax (Google Polymer)
- → Plugin with single item ( october cms )
- → Laravel - Custom User Fields
- → How to update a column after an expiration date in MySQL?
- → Laravel 5.1 Custom table names and field names
- → React child component is not firing on click event