Open adrianbj opened 8 years ago
Adrian, the $user API variable is bunched in with all the other system pages, which typically don't have output formatting enabled since they aren't pages with URLs that would be output on the front-end. I can see a case for the $user one to have it enabled by default, though only if someone has modified the template to have more fields than the system provides with the user template. However, I wouldn't want to introduce a change like that to existing installations, because who knows what it might break. I'll look into finding a way to make it a configuration option.
Thanks Ryan - I see your point - perhaps it doesn't need to be configurable as long as it is clearly noted in the docs.
Is there a logical reason why this works without needing to turn formatting on?
$u = $users->get($user->id);
echo $u->avatar->url;
I understand what is going on, but it does seem weird.
This just bit me out of nowhere. Everything seemed like it was working until I opened a page that coincidentally didn’t load the logged-in user independently. For example, this will output the image url twice if the page was created by user()
, but otherwise the second line will throw “Pageimages::size does not exist”.
echo page()->createdUser->avatar->size(100, 100)->url;
echo user()->avatar->size(100, 100)->url;
To modify @adrianbj’s example, this works, but ONLY if you leave the seemingly useless first line. If the first line is removed, it won’t throw but silently output the url to the user page’s assets directory, not the image.
users()->get(user()->id);
echo user()->avatar->url;
Will this fix itself if I move all users to a custom template and/or parent?
Will this fix itself if I move all users to a custom template and/or parent?
@JanRomero - Not sure if you have used the custom user parent/template setup before but I would caution you to read through these first:
https://github.com/processwire/processwire-issues/issues/1455 https://github.com/processwire/processwire-issues/issues/1478 https://github.com/processwire/processwire-issues/issues/1469 https://github.com/processwire/processwire-issues/issues/1457 https://github.com/processwire/processwire-issues/issues/1456 https://github.com/processwire/processwire-issues/issues/1452
I find the feature invaluable, but it does have its quirks.
I find the feature invaluable, but it does have its quirks.
I don't want to take this too far off-topic, so sorry in advance, but this is exactly why I've never been able to use it. Tried a couple of times, got frustrated, gave up.
I know for a fact that it works and is very nice for some use cases (we use it a lot in our registry product), but personally I've always ended up with a) user and b) separate but somehow linked page if I need something that isn't applicable to all / most users, or needs to be publicly viewable.
I get that this feature technically works and it's probably not the top priority in terms of core development, but would love to see it get some attention in the future. As it is right now, it works for some use cases, but it's not the general purpose feature I'd love to have :)
Thanks for the refresh, I had meant to make this configurable a long time ago. I'll add a $config->userOutputFormatting = false;
configuration option so that you can optionally set it to true (affecting the $user API var) if it better suits your needs.
https://processwire.com/talk/topic/13141-image-field-in-user-template-not-behaving-normally/
I just tested on a clean install and this seems to be a longstanding bug as far as I can tell.