Jump to content
a-ok

Page field, or similar, but for repeater rows?

Recommended Posts

Hi folks,

I use the Page field quite often to cross reference data on the sites that I build and they are super useful, but I have a question regarding doing the same thing but with a repeater field? I know a lot of you know might think that perhaps I am using the repeater field wrongly and that the data should in fact be pages but I believe in this case that the repeater field is the best option.

I have a Publications section on my site, which include image and title only, for each. I had thought about making each Publication a 'page' but then all you have on each page to edit is an image and thought this was maybe a bit clunky to do and a repeater would be better? So, if I make Publications a repeater... can I grab a specific 'field' from the repeater in a Page-like field? So, on another section, say Projects, I would be able to link a specific Publication to a Project via a dropdown field. You know?

Let me know if you think there's a better way of doing this... it might be that if I ever need to cross reference another piece of data (an entry in the CMS) then it needs to be part of a 'page' and then easily selectable via a Page Field.

Thanks!
R

Share this post


Link to post
Share on other sites

Also, see attached. Is there a way to do the following but have each 'entry' within the year selectable via a Page field or similar? Or would each 'exhibition' need to be a page? It's only text so seems a little weird to do it this way.

5vcgShu.png

Share this post


Link to post
Share on other sites

Hi Richard. Guess what? The repeater rows ARE pages :)  They are stored under the Admin area in the page tree. So they could technically be selected in a page field, but I'm not sure how the titles would be handled or how you would select for all pages if the repeater appears on multiple pages. It would probably be a bit clunky, but you might be able to get it to work they way you want if you play around with it.

I think the better way to go would be using a PageTable field, and then hiding the page list somewhere out of the way in the page tree. You would have more control that way. But then you'd have to use the modal windows for updating values, which may not be what you want.

EDIT: Since you can specify a field other than the title to be visible in the Page select input and all of the repeater pages that use the same repeater field are (I think) stored together, maybe repeaters would be the more elegant solution for this after all. Just keep in mind that "plain old pages" are always the more flexible and scalable option if your needs change down the road. 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the reply!

Are you sure they are? So, for example, how could I use the 'Custom selector to find selectable pages' to grab a repeater? You see what I mean?

Share this post


Link to post
Share on other sites

They are pages. Look for them under "Repeaters" inside the admin page in the tree.

Repeater pages are under a page with the name "for-page-1234" (1234 is the ID of the page that holds the repeater field) under a page named "for-field-123" (being 123 the id of the repeater field. You can see it o  the URL when editing the field). This means that you can easily get all pages from a repeater field in a page by using the selector:

$pages->find("parent=/processwire/repeaters/for-field-123/for-page-1234")

Or even construct that selector dynamically when needed:

$pages->find("parent=/processwire/repeaters/for-field-130/for-page-{$page->id}")
  • Like 5

Share this post


Link to post
Share on other sites

Ah right, yes thanks this makes sense. In the 'Custom selector to find selectable pages' field, for a PageField, I have put:

parent=/home/repeaters/for-field-112/

but it returns nothing... is this the actual path to admin repeaters?

Share this post


Link to post
Share on other sites

You don't need "home" and you need the name of the "Admin" page in it's place. By default, the name of the Admin page is "processwire" so you would want:

parent=/processwire/repeaters/for-field-112/

  • Like 2

Share this post


Link to post
Share on other sites

Replace home by the name of your admin page

Share this post


Link to post
Share on other sites

Thanks, guys. This all works great! And I can choose the label to be the title field within the repeater... ALL GOOD!

  • Like 1

Share this post


Link to post
Share on other sites

You can actually select repeater pages by their template:

$pages->find("template=repeater_fieldName"); 
  • Like 4

Share this post


Link to post
Share on other sites

Thanks for this LostKobrakai. So if I replaced the following, in the 'Custom selector to find selectable pages'

parent=/login/repeaters/for-field-144/for-page-1033/

for

template=practice_publication

it not longer works...  should it? Or have I got the wrong end of the stick...

Share this post


Link to post
Share on other sites

Thanks, LostKobrakai but it still doesn't seem to work; are you sure it's template=repeater_name?

template=practice_publication, include=hidden

Share this post


Link to post
Share on other sites

You can check this by enabling "view system templates" in the template overview. This should show those automatically created templates.

Edit: you need to literally add "repeater_" in front of thr name.

  • Like 2

Share this post


Link to post
Share on other sites

Amazing... thanks! I didn't think you meant 'repeater_' but by enabling the View System Templates it makes sense now :) A great solution, thoughts!

Share this post


Link to post
Share on other sites

I ran into the same problem. The selector as mentioned by LostKobrakai works fine for me as admin. But for other users the field appears always empty in Processwire.

What permission do i need to give to the user-role to make it work for them? And how do i do that?

Share this post


Link to post
Share on other sites

Ok, i was now able to solve this on my own:

I had to change "..., include=hidden" to "..., include=all" so it works for non-admin-users.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By carlitoselmago
      It's been twice this year as a PW developer where clients have asqued me to have a way to put content on specific coordinates of a picture. Something like what image maps are made of. But not necesarly on links, sometimes text, sometimes images and links. 
      So I've been thinking to build an inputfield for that purpose. But I'm not sure how could it be the most flexible so I can share it in github/modules page.
      Ideally it would need to work like a repeater field where you start uploading an image and then adding any custom field like title, url etc. So the user could add multiple elements floating over that image.
      Does anybody here know the ideal way to start the arquitecture of something like that? I could just hardcode the fields I need for the website I have to code this month but it would be nice to be something more flexible.
    • By fruid
      how to get all the subfields of a repeater field generically? I'm not talking about a specific field that I know the name of, that's easy, I'm trying to access them in general in the $fields variable itself.
      Better yet, how to access them by type?
    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate multible repeater items from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Configurable dialogs for copy and paste Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Attention, please note!
      Nested repeaters cannot be supported technically. Therefore a check is made to prevent this. However, a nested repeater can only be detected if the field name ends for example with "_repeater1234". For example, if your MatrixRepeater field is named like this: "content_repeater" or "content_repeater123", this field is identified as nested and the module does not load. In version 2.0.1 the identification has been changed so that a field ending with the name repeater is only detected as nested if at least a two-digit number sequence follows. But to avoid this problem completely, make sure that your repeater matrix field does NOT end with the name "repeater".
      Changelog
       
      2.0.1
      Bug fix: Thanks to @ngrmm I could discover a bug which causes that the module cannot be loaded if the MatrixRepeater field ends with the name "repeater". The code was adjusted and information about the problem was provided 2.0.0
      Feature: Copy multiple items at once! The fundament for copying multiple items was created by @Autofahrn - THX! Feature: Optionally you can disable the copy and/or paste dialog Bug fix: A fix suggestion when additional and normal repeater fields are present was contributed by @joshua - THX! 1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module (Version 2.0.1)
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: https://modules.processwire.com/modules/inputfield-repeater-matrix-duplicate/
      > Old stable version (1.0.4): https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate/releases/tag/1.0.4
    • By arnd
      Hi,
      I have a repeater with some images in it.
      As Superuser I can work with the Actions (rotate...). But my Users with lower Rights can't use this Actions.
      The same User can use the Actions on images outsite a Repeter-Field. So I think it's not a Problem of Rights-Management but from Images in Repeater Fields.
      ProcessWire 3.0.164.  Bug? Or can I manage this in the settings?
      Thanks in advance
    • By Robin S
      This is a module I made as an experiment a while ago and never got around to releasing publicly. At the time it was prompted by discussions around using Repeater fields for "page builder" purposes, where the depth feature could possibly be used for elements that would be nested inside other elements. I thought it would be useful to enforce some depth rules and translate the depth data into a multi-dimensional array structure.
      I'm not using this module anywhere myself but maybe it's useful to somebody.
      Repeater Depth Helper
      This module does two things relating to Repeater fields that have the "Item depth" option enabled:
      It enforces some depth rules for Repeater fields on save. Those rules are:
      The first item must have a depth of zero. Each item depth must not be more than one greater than previous item depth. It provides a RepeaterPageArray::getDepthStructure helper method that returns a nested depth structure for a Repeater field value.
      Helper method
      The module adds a RepeaterPageArray::getDepthStructure method that returns a multi-dimensional array where the key is the page ID and the value is an array of nested "child" items, or null if there are no nested children.
      Example

      The module doesn't make any assumptions about how you might want to use the depth structure array, but here is a way you might use it to output a nested unordered list.
      // Output a nested unordered list from a depth structure array function outputNestedList($depth_structure, $repeater_items) { $out = "<ul>"; foreach($depth_structure as $page_id => $nested_children) { $out .= "<li>" . $repeater_items->get("id=$page_id")->title; // Go recursive if there are nested children if(is_array($nested_children)) $out .= outputNestedList($nested_children, $repeater_items); $out .= "</li>"; } $out .= "</ul>"; return $out; } $repeater_items = $page->my_repeater; $depth_structure = $repeater_items->getDepthStructure(); echo outputNestedList($depth_structure, $repeater_items);
       
      https://github.com/Toutouwai/RepeaterDepthHelper
      https://modules.processwire.com/modules/repeater-depth-helper/
×
×
  • Create New...