Jump to content

Repeater with five fields generates sixten outputs


felted
 Share

Recommended Posts

Hi,

i have tow repeaters on a site with five fields.

 

foreach ($child->Portrait_Repeater as $data) {
					$i = 1;
					foreach($data as $person_data){
						$content .= $i.": ".$person_data."<br />";						
						$i++;
					}
	}

The foreach outputs sixten fields:

1: 1113
2: 1570437779-0381-1
3: 1
4: 0
5: 0
6: sort
7: 41
8: 41
9: 1570437779
10: 1570439027
11: 1570437833
12: max.jpg
13: Max Mustermann
14: Rektor
15: 1234 - 56789
16: info@maxundmoritz.de

Where are the first 11 fields coming from?

Thanks, Detlef

Link to comment
Share on other sites

Behind the scenes, repeater entries are individual pages, so when you iterate over an entry (your second loop), you iterate over all the properties of the repeater page. You can see that if you change your code to:

foreach ($child->Portrait_Repeater as $data) {
					$i = 1;
					foreach($data as $prop => $person_data){
						$content .= $i.": $prop => ".$person_data."<br />";						
						$i++;
					}
	}

The solution is to remove the inner loop and address the properties by name instead, like $person_data->email, $person_data->position etc.

  • Like 3
  • Thanks 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...