This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Panicintrinsica
Panicintrinsica

First off, I’ve not really worked with twig or laravel in the past (mostly just HTML, CSS, PHP and SQL) so assume that I know nothing about either. Without going into a needlessly long explanation, I have a model with a repeater that lets me add/edit/reorder an array. Checking the database, that seems to be working, since I found the following:

{
"1":{"label":"Header 1","data":"Text 1"},
"2":{"label":"Header 2","data":"Text 2"}
}

The problem is, while there’s apparently a way to use the builder to add this information, I can’t find a way to display it. Anytime I try to fetch that field with either of builder's components, "Record details" or "Record list", I get the following error(s)

An exception has been thrown during the rendering of a template ("Array to string conversion").

In both cases, the highlighted line is

{{ attribute(record, displayColumn) }}

I assume the issue here is just that it’s trying to use the wrong function and it needs to be changed to something that can deal with an array, but I have absolutely no clue what It should be using here or even how to go about searching for a solution, since, again, I know next to nothing about twig/laravel.

So, if anyone knows how to fix this particular problem and can explain it to me like I am a mentally deficient parrot, I'd be very grateful.

alxy
alxy

The Repeater form widget will result in an array as model data. That's why attribute(record, displayColumn) will actually return an array, that can obviously not be rendered as string.

Try the following instead:

{% for line in attribute(record, displayColumn) %}
  {{ line.label }}
{% endfor %}

More information about twigs for loop can be found in the official documentation: http://twig.sensiolabs.org/doc/tags/for.html

Panicintrinsica
Panicintrinsica

That worked perfectly. Thank you very much!

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.