Are repeated fields possible?


First off I’m pretty new to Kirby, I’m still testing it out. Go easy on me.
So far I’m loving it, makes a refreshing change from WordPress :slight_smile:

I have a question about repeated fields in Kirby, I’m not sure if I’m wording my searches properly (or this question), as I’m not getting any useful results. :blush: I am wanting to achieve something like what Advance Custom Fields’ Repeater Field can achieve in WordPress.

I’d like to create a page template the could have multiple ‘sections’ on the same page. The numbers of sections could change from page to page, and whats in these sections could also change. In this example, each section has a title, text and a image src.

Now I know could call a bunch of custom fields, like this for example…

Title1: The Title of the first section
Text1: The paragraph for my first section.
ImageSrc1: /content/2-test-sections/1-test-section/myfirstimage.jpg
Title2: The Title of the second section
Text2: The paragraph for my second section.
ImageSrc2: /content/2-test-sections/1-test-section/mysecondimage.jpg

But some pages might have, say 10 ‘sections’ so it seems stilly to have to create 10 “Titles:”. Also if I decide later to add an 11th section on a new page, I’d have to re-edit the template.

So my question is, is there some php that can count the number of times title: appears and create a new section for this, not dependant on a actual number?
Also say there are 3 sections, but the 3rd doesn’t have an image src, it would just ignore outputting the html for the image?

My php skills are pretty basic but I’m sure this should be easy to achieve, any help/links/advice would be very much appreciated.
Thanks Rob

What your are looking for is probably sth suggested in this post:

However, something like that is not currently possible.

As regards repeated fields, these are possible with Kirby. If you can live with fields that are not always all filled for all entries, then you could use the structure field which is even more powerful now with the new toStructure() method

1 Like

Thanks @texnixe , I saw this post as a related article when I typed in the title, I like suggestion, but I was hoping I wasn’t asking for something much less technical as this.

I’m not sure I fully understand the Structure fields, but I’ll have a play with that. I think it might be what I’m after. toStructure() looks promising too, I’ll have a play with that also :slight_smile:


@rob, if you have any problems with the structure field, just ask :smile:

1 Like