Jump to content

Can you have a repeater field within a repeater?


Brian Larson
 Share

Recommended Posts

I'm trying to use a repeater field within a repeater field and the secondary/internal repeater field does not show up in the Add Field drop down within its parent repeater field Edit > Details page. Looks like it's not built to be nested? Thanks in advance!

P.S. I'm very new PW and love it! All other CMS stuff I do is with WordPress and MODX.

Link to comment
Share on other sites

Technically repeaters can be nested (I've done it before, though disabled it), but it creates so much potential for problems that I didn't think we'd want to support that. Plus considerations for 3rd party Inputfield modules, and the list goes on. The situations where nested repeaters are worth the compromises is pretty rare, as there's usually a better way to accomplish the same thing. Ultimately decided we shouldn't have support for it at this time. But if you can describe what you are trying to accomplish with nested repeaters, I may be able to describe alternative ways to achieve the same thing. 

Link to comment
Share on other sites

  • 3 weeks later...

Hello Ryan and others!  I've got a situation in which I'm hankering to use nested repeaters, and would love anybody's thoughts about alternatives that make sense.

I'm creating a website that needs to display artist CVs with very strict formatting guidelines.  The HTML I'll be outputting will look something like this:

        <div class="section_wrap">
            <div class="section_header">One-Person and Collaborative Exhibitions</div>
            <div class="section_body">
                <div class="year_wrap">
                    <div class="year">2012</div>
                    <div class="year_entry_wrap">
                        <div class="year_entry">Item 1</div>
                        <div class="year_entry">Item 2</div>
                    </div><!--/year_entry_wrap-->
                </div><!--/year_wrap-->
                <div class="year_wrap">
                    <div class="year">2011</div>
                    <div class="year_entry_wrap">
                        <div class="year_entry">Item 1</div>
                    </div><!--/year_entry_wrap-->
                </div><!--/year_wrap-->
            </div><!--section_body-->
        </div><!--/section_wrap-->
        <div class="section_wrap">
            <div class="section_header">Group shows</div>
        
            <!--and so on-->

The nested repeaters I would use if I could would work out something like this:

"section" (fieldtype:repeater)

"section_header" (feldtype:text)

"year_wrap" (fieldtype:repeater)

"year" (fieldtype:text)

"year_items" (fieldtype:text)

 

That way, I could have a template called CV with the field "section" in it, and each CV could be entered as one page, with a page tree structure like this:

Home

CVs

Artist 1

Artist 2

Etc...

The workaround solution I'm thinking about now (though I'm sure there is something better) is to have each section be a different page:

Home

CVs

Artist 1

Section 1

Section 2

Etc

Artist 2

Section 1

Section 2

Etc

Etc

I'm still relatively new to PW and PHP, so if the answer is apologies if this seems like a silly question.  I'm getting close to finishing my first major project with PW and have absolutely loved it, both for the framework itself and for the amazing community.

Thanks in advance!

  • Like 1
Link to comment
Share on other sites

I think that you are on the right track using Pages rather than Repeaters for your sections. Actually, it looks to me like all of this stuff is intended to be output as pages on the front-end anyway, so you may want to avoid using Repeaters entirely. Repeaters are great for specific use cases, but you are far better off using Pages when it comes to anything site-structure related. If I've misunderstood the need to use repeaters here, then one solution you could look at would be to simply include your section_header field in the year_wrap repeater, and specify in your field description that the user should only specify a section header when they want to change it, and to leave it blank otherwise. 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

I am building a restaurant website with ProcessWire and need to have nested repeaters for menu 'sections' and menu 'items' within them. This is a case where I dont want to use pages (as this is the only place I want to output this).

Example nesting:

Menu Section

Menu Item

Menu Item

Menu Item

Menu Section

Menu Item

Menu Item

Menu Item

Menu Section

Menu Item

Menu Item

Menu Item

Any chance I can enable a config option to allow selection of repeater field types within another repeater field input settings?

Link to comment
Share on other sites

Nested repeaters aren't supported because it introduces a high probability of issues. As a result, there isn't a config option to enable it. The repeater code just isn't designed to nest like that. Usually envisioning your structure as a page tree is the best solution for something like this. But if that doesn't work, or you don't want to do it, another route is to make "section" a page reference (select field) within a menu-item repeater. Every repeater item would have a 'section' select where they choose what section the item goes in. Alternatively, the sections could themselves be pages, each with a menu-item repeater. Even if you could nest here, I actually think it simplifies your site a lot to use the page structure rather than repeaters in cases like this, because it adds more clarity to working with the items from the development side. And it is something that is ultimately more scalable (though not sure if that matters in this particular instance). 

Link to comment
Share on other sites

  • 10 months later...

Hey everybody,

i'm checking out processwire and test some use cases. There is one use case where it would be nice to use repeaters within a repeater. Sometimes it's useful to give the user the possibility to build their own pages out of set of content-modules (Like ACF in Wordpress or TYPO3) and order them as they want. With repeaters within a repeater it would be possible to build ("sub")-repeaters as a content blocks. Within the repeater every ("sub"-)repeater could work as a content type for example a textblock, galleryblock and so on. The advantages would be, that the Content Blocks within the Page would be sortable. I really hope, that there is no"bug" in my logic. I'll appreciate to hear your thoughts.

OR Are there other concepts to realize something like that? Please note, that i'm new to processwire. Just in case my question is really stupid. :D

Link to comment
Share on other sites

Hey everybody,

i'm checking out processwire and test some use cases. There is one use case where it would be nice to use repeaters within a repeater. Sometimes it's useful to give the user the possibility to build their own pages out of set of content-modules (Like ACF in Wordpress or TYPO3) and order them as they want. With repeaters within a repeater it would be possible to build ("sub")-repeaters as a content blocks. Within the repeater every ("sub"-)repeater could work as a content type for example a textblock, galleryblock and so on. The advantages would be, that the Content Blocks within the Page would be sortable. I really hope, that there is no"bug" in my logic. I'll appreciate to hear your thoughts.

OR Are there other concepts to realize something like that? Please note, that i'm new to processwire. Just in case my question is really stupid. :D

Check out PageTableExtended - works great for sortable content blocks.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...