Reclus Posted June 21, 2019 Posted June 21, 2019 Hello, there is probably a really simple solution to this but I can't find it ? I want to use an individual repeater on a number child pages and have their content displayed on the parent page, so something like this. - home (repeater_1 and repeater_2 content appears here) - childpage_1 (repeater_1) - childpage_2 (repeater_2) The following repeater code works as intended but only if the repeater is used in the parent page. <?php foreach($page->repeater_1 as $field) { echo "{$field->repeater_heading}"; echo "{$field->repeater_body_content}"; }?> Thanks in advance.
wbmnfktr Posted June 21, 2019 Posted June 21, 2019 Something like this? <?php foreach($page->repeater_1 as $field) { echo "{$field->repeater_heading}"; echo "{$field->repeater_body_content}"; // look for children if( $page->children ) { // for each child foreach( $page->children as $child ) { // the child repeater field output foreach( $child->repeater_1 as $childRepeater ) { echo $childRepeater->fieldName; } } } }?> 1
Reclus Posted June 21, 2019 Author Posted June 21, 2019 Thanks wbmnfktr. I have had partial success by tweaking my original code as so ... <?php foreach($page->child->repeater_1 as $field) { echo "{$field->repeater_heading}"; echo "{$field->repeater_body_content}"; }?> However, this only works for the first child page, so not ideal. I will take a closer look at your suggested code now, thanks again.
Reclus Posted June 22, 2019 Author Posted June 22, 2019 After a bit more learning and poking around the forum I managed to solve this. Here's the working code I ended up with - just in case it helps anyone else. <?php $lineup = $pages->find("template=festival"); // my template foreach($lineup as $acts) { foreach($acts->festival as $field) { // my repeater field echo "{$field->repeater_heading}"; echo "{$field->repeater_body_content}"; }} ?>
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