Jump to content

Call to non-object width()


opalepatrick
 Share

Recommended Posts

Anyone have any idea why I am getting a call to a non-object width(), size() on this image:

foreach ($pages->get("template=case-studies")->children() as $child) {
  $logo = $child->logo->width(250);
  echo "<img class='floatleft' src='" . $logo->url . "' />";
  echo "<h2>" . $child->title . "</h2>";
  echo "<p>" . $child->body . "</p>";
}

the logo field is an image field for one image only. If I remove the width or size parameter all works fine. Surely $child->logo is still referring to an object? Or am I misunderstanding things?

Link to comment
Share on other sites

As with most code in this forum this is not real and best practice code as macrura also points out. Once there's no image it will fail.

Also body I asume is a RTE field and will have a <p> already.

  • Like 2
Link to comment
Share on other sites

Thank you for all your replies. I had checked for the image and its settings. So as I stated in my post, it was for a single image, but I should have been more explicit instead of just saying that when I removed width() everything was 'fine'. What I should have said was that the image appeared in original unchanged form. This was why I was baffled because the image appeared unless the width() or size() parameter was added to the code.

However... when I added macrura's check, the width() parameter worked. I removed the check and it still worked and no problem since. I know something must have changed but I have not got a clue why. Suffice to say that everything now works as I would expect. So rather than waste everyone's time any more, I consider it solved :-)

Once again. Thank you.

PS, You are right Soma the body field is in fact Markup and should not be wrapped in <p>

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