bowenac Posted November 11, 2014 Posted November 11, 2014 (edited) NM figured it out typo... Delete if you want. Hello all, started playing with processwire last night, been developing for wp for years and so far I am liking some things with PW. Currently I edited the users template and added some profile fields etc. I am able to get all the fileds except the image field. This is what I am currently trying. $page->createdUser->images->first(); This is not working for me. Is this not the correct way to get a user profile image? Edited November 11, 2014 by bowenac
Martijn Geerts Posted November 11, 2014 Posted November 11, 2014 How is you image field setup? Single or array ? $createdUser = $page->createdUser; // Assumed the images field is an array of images. (depending on field settings) $image = $createdUser->images->first(); if ($image) { echo "<img src='$image->url' alt='$image->description'>"; }
Jan Romero Posted November 11, 2014 Posted November 11, 2014 Your images field is probably set to Automatic because you use it for multiple images in another template, but for user profiles you limited it to 1, which means you don’t have to use →first(). You can also configure the field to always give you an array, regardless of the max-setting. Then you have to write →first() every time, but you’ll always know what you’re working with. Maybe a single image should throw a descriptive exception when accessed like a WireArray.
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