Jump to content

Problem outputting repeater


alexpi
 Share

Recommended Posts

Hello

I have the following code:

$houses = $pages->get('/houses/')->children('limit=6');

foreach ($houses as $house) {
  echo "<li>";
  foreach ($house->repeater as $repeater_item) {
    echo $repeater_item->repeater_field;
  }
  echo "$house->title";
  echo "<a href='{$house->url}'>";
  echo "<h2>{$house->title}</h2>";
  echo "<img src='{$house->house_thumbnail->url}' />";
  echo "</a>";
  echo "</li>";
}

The problem is that I can't output the nested foreach(). I get a 'Invalid argument supplied for foreach()' error.

Do I have a syntax error?

Link to comment
Share on other sites

Nope, your syntax is correct.

But it looks like the template for page $house does not have a field called 'repeater' and thus foreach gets something it can't iterate (null I guess). Check the name of the repeater field and it should work just fine.

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

×
×
  • Create New...