Elías Gómez Posted December 13, 2016 Share Posted December 13, 2016 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 More sharing options...
Sergio Posted December 13, 2016 Share Posted December 13, 2016 The image field default setting is to output an array, so if you only want to output one image of the page, try on your loop: $event->images()->first()->url; 3 Link to comment Share on other sites More sharing options...
Elías Gómez Posted December 14, 2016 Author Share Posted December 14, 2016 Thank you very much, but it doesn't work for me. It works for the $page variable (the homepage), but it doesn't work in the single $event of my loop (that is a foreach). What can I been doing wrong? By the way, it seems that images of $page is a property and not a method. Link to comment Share on other sites More sharing options...
Robin S Posted December 14, 2016 Share Posted December 14, 2016 @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/ 3 Link to comment Share on other sites More sharing options...
Elías Gómez Posted December 14, 2016 Author Share Posted December 14, 2016 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 1 Link to comment Share on other sites More sharing options...
Sergio Posted December 15, 2016 Share Posted December 15, 2016 @Elías Gómez, great that you sorted that out! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now