alejandro Posted July 14, 2013 Share Posted July 14, 2013 Hello, absolutely newbie here, understanding PW. One problem i can´t solve, in a template file i want to output an image field, so following the docs: <?php if($page->featuredImg) echo "<img src='{$page->featuredImg->url}'>"; ?> but what i get is the url whithout the image file name at the end: /IntegralPW/site/assets/files/1009/ so the image is not displayed. The image file exits in the directory, the template file has been assigned to the page, the field to the template...¿? Didn´t find any reference about this in the forums, maybe a miss out something in the docs? Thanks in advance. Link to comment Share on other sites More sharing options...
diogo Posted July 14, 2013 Share Posted July 14, 2013 Hello ideagonal, welcome to the forum! My guess is that the field that you are trying to output is a multiple images field. Try this, and you'll see it will work: echo "<img src='{$page->featuredImg->first()->url}'>"; What I did there was output explicitly the first image in the array. But if you are planning to have only one image on that field, the best would be to limit it to 1 in the field option. This will transform this field in a single image field, which would work straight with the code you used. For how to use multiple images, read this: http://processwire.com/api/fieldtypes/images/ 1 Link to comment Share on other sites More sharing options...
teppo Posted July 14, 2013 Share Posted July 14, 2013 (edited) What you're seeing happens because your featuredImg returns "Pageimages" (multiple images) instead of one Pageimage object and that URL points to where they all reside. I'm guessing your featuredImg isn't limited to only one image via field settings? You need to do either that or specify which image you want, like this: <?php if(count($page->featuredImg)) echo "<img src='{$page->featuredImg->first()->url}'>"; ?> By the way: when dealing with multiple images / Pageimages object, you'll have to check with count() if any images actually exist. With one Pageimage you can simply check if $page->featuredImg evaluates to true (like you did in your code above.) Edit: looks like I'm too slow today.. Edited July 14, 2013 by teppo 1 Link to comment Share on other sites More sharing options...
alejandro Posted July 14, 2013 Author Share Posted July 14, 2013 My guess is that the field that you are trying to output is a multiple images field. So it is, problem solved. Worst thing, i had read the docs about single and multiple images fields... mmm, guess is a newbie "thing", stuck in a problem with the solution right in front of you. Thank you! 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