Jump to content

Recommended Posts

Posted (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 by bowenac
Posted

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'>";
}
Posted

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.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...