Jump to content

Nested repeater


Markus Thomas
 Share

Recommended Posts

Hi, when i use nested repeater in PW 3 it will only output the first entry from the second repeater.

Code:

		<?php foreach ($page->first_rep as $c):	?>
		<?php echo $c->fields; ?>
			<?php foreach ($c->second_rep as $p):	?>
				<?php echo $p->fields; ?>
			<?php endforeach; ?>
		<?php endforeach; ?>

Can anybody help me?

Link to comment
Share on other sites

Hi @Markus Thomas, and welcome to the forums.

In your code example, it doesn't really make sense to do...

echo $c->fields;

...or...

echo $p->fields;

$page->fields is the same as $page->fieldgroup, which the API docs explain as follows:

Quote

Fieldgroup used by page template. Shorter alias for $page->template->fieldgroup

So the fieldgroup is the same for every page that uses the template (i.e. every Repeater item/page in the Repeater field), and you can't simply echo a fieldgroup object in any case.

I think instead you want to get the individual subfields you have added to the Repeater field, and you normally do this by getting the subfields by name. For example:

<?php foreach ($page->first_rep as $c): ?>
    <?php echo $c->title; ?>
    <?php echo $c->body; ?>
    <?php foreach ($c->second_rep as $p):   ?>
        <?php echo $p->my_other_field_name; ?>
    <?php endforeach; ?>
<?php endforeach; ?>

 

  • Like 2
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...