jothanne

Items of Page Reference Field from field within Repeaters

Recommended Posts

I have the following page and field setup:

root_page (Page)
|
|- colors_page (Page)
|  |
|  |- type_repeater (Repeater Field)
|     |
|     |- color_repeater (Repeater Field)
|        |- colorname_text (Text Field)
|        |- coloropt_options (Select Options Field / Multiple values)
|           (1=usable, 2=preferred)
|
|- products_page (Page)
   |
   |- product_repeater (Repeater Field)
      |- product_color (Page Reference Field)

Now i want to fill the entries of the 'product_color'-field with only the color names ('colorname_text'-field) of the colors which are 'usable' (value=1) corresponding to the 'coloropt_options'-field within the nested repeaters 'type_repeater' and 'color_repeater' of the 'colors_page'.

I researched and tried a lot, but cant't really get around this problem. As a temporary workaround i replaced the repeater fields by subpages - but that isn't what i want in the end. And now i hope for a helping hand to give me the essential advice or hint.
Thanks a lot in advance.

Share this post


Link to post
Share on other sites

Hey @jothanne,

Welcome to ProcessWire/the forums.

I don't get your setup entirely. Do you have a repeater nested within a repeater? i.e., is type_repeater a repeater field that also contains the repeater color_repeater?

Normally for the sort of logic you are after (for page fields), you can use the Custom PHP Option (see the input tab of your page field product_color). I'm not sure this solves your problem though as I don't fully grasp your setup.

Share this post


Link to post
Share on other sites

Hi kongondo,

Thanks a lot for your reply! Yes - the type_repeater (repeater field) contains the repeater-field color_repeater.

I saw this 'Custom PHP Option' and suspected that might be the way to go, but can't really find out, how to adapt this for my use case. Maybe you can give me a hint or a small code example to do the trick.

Share this post


Link to post
Share on other sites

OK, I get you.

On 9/13/2018 at 8:44 AM, jothanne said:

Now i want to fill the entries of the 'product_color'-field with only the color names ('colorname_text'-field) of the colors which are 'usable' (value=1) corresponding to the 'coloropt_options'-field within the nested repeaters 'type_repeater' and 'color_repeater' of the 'colors_page'.

My understanding is that you will have ONE colors page which will hold ALL your colours whereby the different colours are defined within the repeaters?  You then want these colours (the ones that are usable) to be individually selectable within page reference field product_color? Meaning your page field will show  brown,green,red, etc? Unless I've missed some recent PW feature, you can't do that. Only pages are selectable in page reference fields. So, you would have to change your approach. 

Let me know if I'm still missing the mark :-).

 

Share this post


Link to post
Share on other sites

Hi kongondo,

your understanding is completely right. Sadly to read that this isn't realizable the described way - but I suspected something like that. So I went the way with my initially described - now not so - 'temporary workaround'.

It seems that my fault was to think of the repeaters as a special kind of subpages-layer with a somehow similar behavior. OK - maybe the future will bring this feature since I'm a big fan of the repeater-technique and the associated clear arrangement in the pages tree of the user interface.

Thank you for your efforts to clarify the issue.

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 karian
      I don't know why multiple instances (repeater_repeat_columns1, repeater_repeat_columns2, ...) of my repeater field are displayed inside Template field (see image).
      Is there a way to clean/reset it ?
       

    • By dragan
      I'm trying to update certain repeater fields with a hook. This almost works, but is somehow buggy.
      Each repeater is supposed to represent a row: service, remarks, number of days, day-rate, row total.
      The last repeater should then show the grand total.
      I've tried this:
      $this->addHookAfter("Pages::saveReady", function (HookEvent $event) { $page = $event->object->getPage(); if ($page->template->id == 89 && $page->parent->parent->id == 11180) { $repeater = $page->offer_calc_repeater; $itemCount = $repeater->count(); $c = 0; $grandTotal = 0; foreach ($repeater as $rep) { if($c < ($itemCount - 1) ) { if (!empty($rep->days) && !empty($rep->daily_rate)) { $num_days = $rep->days; $day_rate = $rep->daily_rate; $row_total = $num_days * $day_rate; $rep->row_total = $row_total; $grandTotal = $grandTotal + $row_total; $page->save(); unset($num_days); unset($day_rate); unset($row_total); $c++; } } if ($c == $itemCount) { $rep->row_total = $grandTotal; } } } }); Most calculations are correct, but:
      The first one is empty.
      The second one is calculated wrong.
      I've tried typecasting (float), or checking with strlen instead of !empty, but that doesn't make any difference.
      Is the Pages::saveReady the ideal hook for such stuff? (placed in site/ready.php).
      Also, I get an error message: Session: Method Pages::getPage does not exist or is not callable in this context.
      Any ideas? Would you perhaps rather do stuff like this via JS?
    • By louisstephens
      Ill be honest, I am a bit unsure how accomplish this. I have a repeater (dev_repeater) that contains an image field set to 1 image. Nested within this repeater, is another repeater (dev_child_repeater) that allows a user to add in some urls. However, there is also a hidden field that I am trying to pass the parent repeater's image path. 
      I know I can output all the data by using:
      <?php foreach($page->dev_repeater as $repeater) { foreach($repeater as $url) { # do some stuff } } ?> For the life of me, I can not figure out how to obtain the image url in my php to pass to a variable inside the nested foreach loop. Hopefully this made some sense.
    • By Xonox
      Hi,
      I have a template that it's working fine in development, however I can't get it to work on production! It shows every information inside repeater fields except the images.
      Here's the template:

      These are the circuit_day_image settings:

      This is the code:
      <?php foreach($page->circuit_days as $circuit_day) { if($circuit_day->circuit_day_image) { $day_image = $circuit_day->circuit_day_image->size(300, 300)->url; echo '<img src="' . $day_image . '" />'; } else { echo 'No image! :('; } echo '<h2>' . $circuit_day->title . '</h2>'; echo $circuit_day->body; } ?> I always get "No image! :("
      I think I'm doing everything right!
      Anyone else with a similar problem?
      Update
      After uploading the production database into my server, the images stopped working. It can be one of two problems:
      1. Bad field configuration;
      2. Something wrong with the Database.
      I can't find the problem. Any suggestion is welcome, thanks,
      Update 2
      I forgot to upload the images. It's working on dev and not on production. Still no clue!
      Clue 1
      When I insert
       <pre><?php print_r($circuit_day); ?></pre>
      On development I get a clean list for each repetition:

      However, on production, the command gets on a weird recursive loop that takes forever (it even slows the browser to a halt):

      What might be going on?
    • By burning
      Hi All, maybe a really stupid question, but is there a way to sort repeater items on -created?
      Like $page->social_activity('limit=10,sort=created'), with 'social_activity' as the repeater field?
      Tried this but it didnt work 😞 
      Any help appreciated!