Jump to content

foreach error help?


Roych
 Share

Recommended Posts

Hello,

What is wrong here, Im getting an error. It works but tracy shows error on first line.

<?php foreach($pages->get('/home/')->ozadje_strani as $bck): ?>
	<?php $image = $bck->bgimage->first(); ?>
		<img src="<?=$image->url; ?>" alt="<?=$image->description; ?>" />
<?php endforeach; ?>
PHP Warning: Invalid argument supplied for foreach() ...

Thank you

R

Link to comment
Share on other sites

Looks fine to me. I wouldn't worry about it if it's working. If you wanted to take the $pages->get('/home/')->ozadje_strani and put it in a variable that might fix it, but I'm not sure because it looks fine. 

  • Like 1
Link to comment
Share on other sites

13 minutes ago, Tom. said:

@adrian I guess if it's working, he must have a page called Home? Maybe he has a splash screen before hand. Strong one. 

Yeah, I guess you must be right. Maybe the ozadje_strani image field is set to return a single image which is why it can't be foreach'd?

Actually, I guess it's a repeater field and bgimage is the image field - I don't know ?

  • Like 2
Link to comment
Share on other sites

4 hours ago, Roych said:

$image = $bck->bgimage->first();

You should always make sure you actually do have an image (except when it's a required field). Do an if() first, maybe the fields are empty? 

  • Like 2
Link to comment
Share on other sites

thanks for answers, I got it. It was a repeater, and had no image in it. I somehow made two of the same repeater field and somehow lost one which had no image in it. I deleted the field and it's fine now.

Thank you all

R

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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