Bike Posted March 24, 2021 Share Posted March 24, 2021 Hi everyone, on some preferences template there is a repeater field containing fields like 'link' and 'url' (and maybe some more). That repeater field is populated by the client. On another template I'd like to have a select field which outputs the repeater's content each as an option so I can have it on the page like $select->link, $select->url, $select->whatever_is_in_the_repeater_field I think this should acutally be a common thing to do but I don't know how to accomplish it. Any ideas? Thanks ? Link to comment Share on other sites More sharing options...
Outward Posted March 25, 2021 Share Posted March 25, 2021 If I'm reading this right, you can do this by creating a page reference and specifying "template=repeater_yourfield". You should be fine in terms of access, but you will want to test using their role if they aren't superusers. If the select box is blank for the user you can use a custom find for the page reference and add 'include=all' or check permissions. Link to comment Share on other sites More sharing options...
Bike Posted April 1, 2021 Author Share Posted April 1, 2021 Thanks @outward, what I actually need (in the admin) is a repeater with a various amount of fields and this repeater to be connected to a select field. I am not quite sure if I can achieve this with your suggestion. Maybe you or someone else has another thread on hand?! Thanks! Link to comment Share on other sites More sharing options...
gebeer Posted April 1, 2021 Share Posted April 1, 2021 @Bike already put you on the right track. I have an example setup that does just this: pull values from a repeater field and display them in a select dropdown. Here's how I made it work. 1. have a repeater field called 'repeater' on a template. The repeater field can have as many fields on it as you like. Mine only has one field named 'headline' 2. make some entries to that field 3. setup a page reference field, mine is named 'selectfromrepeater'. It has Single Page selected in Details tab. In the Input tab, I have following settings See the Label field? Here I have entered the field 'headline' from my repeater field. In your case you can enter 'link' or 'url' 5. I'm using the Custom PHP Code option to retrieve the selectable pages, so in my site/ready.php file I placed this hook: $wire->addHookAfter('InputfieldPage::getSelectablePages', function ($event) { if ($event->object->hasField == 'selectfromrepeater') { $event->return = $event->pages->find('template=repeater_repeater'); } }); Now when I add the new field 'selectfromrepeater' to a template and edit a page with that template, I get something like this: If you wanted to retrieve the selection via API in a template file, you would do $page->selectfromrepeater->headline // or ->url in your case Hope that helps Link to comment Share on other sites More sharing options...
3fingers Posted April 1, 2021 Share Posted April 1, 2021 Quote $wire->addHookAfter('InputfieldPage::getSelectablePages', function ($event) { if ($event->object->hasField == 'selectfromrepeater') { $event->return = $event->pages->find('template=repeater_repeater'); // Why 'template=repeater_repeater' ? } }); @gebeer Where does 'template=repeater_repeater' comes from? Link to comment Share on other sites More sharing options...
gebeer Posted April 1, 2021 Share Posted April 1, 2021 5 hours ago, 3fingers said: Where does 'template=repeater_repeater' comes from? My repeater field's name is 'repeater'. So the template name of pages that this repeater creates in the background is 'repeater_repeater'. If my repeater field was named 'myrepeaterfield' then the template would be 'repeater_myrepeaterfield'. Repeater fields create one page for each repeater entry to store the data. Those pages are located in the page tree under Admin->Repeaters. In my case it looks like If you edit one of those pages, you can see the template name that PW creates automatically 1 Link to comment Share on other sites More sharing options...
3fingers Posted April 1, 2021 Share Posted April 1, 2021 Thanks @gebeer, I've used repeaters (and repeater matrix) a ton and never looked at their corrispettive pages. Now it all makes sense. Great explanations by the way, kudos! ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now