Jump to content

[Solved] How to get an image from the elements of a $pages->find array?


Elías Gómez
 Share

Recommended Posts

I have been trying everthing about images. I have read the documentation about the field itself, some threads, a tutorial, and the cheatsheet.

I am creating an events portal, and I have a template called Event, with an Image field for the poster of the event.  In the homepage I am listing the events, and I am able to output the Tiitle and the Date (with is another field), but I am not able to output the poster.

How can I do this? I am missing something? If you need any other information, just tell me.

Thanks in advance!

Link to comment
Share on other sites

@Elías Gómez, can you post the code you are using to loop over your event pages? It's hard to offer much advice without seeing that. Also let us know what you have selected for the "Formatted value" in the settings of your image field.

As a general tip, if you spend a little time getting to know the Tracy Debugger module you will find it very valuable for investigating these kinds of issues.

https://processwire.com/blog/posts/introducing-tracy-debugger/
http://modules.processwire.com/modules/tracy-debugger/

 

  • Like 3
Link to comment
Share on other sites

I have done it! The error is that I was naming the property images, instead of the name of the image field itself, ie. poster_image. So now I have something like:

foreach ($events as $event) {
	echo "<img src='$event->poster_image->url()'>";
}

I don't need the first() method because I have limited the field to only 1 image.

@Robin S, I was repling when you replied :P

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