Jump to content

Repeaters on Child pages


Reclus
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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;

        }
        
      }
      
  }
    
 }?>

 

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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}";

}}
?>

 

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...