Hi. I’m trying to set a user’s preview image to be an image from a files section (called image
) and I’ve already seen multiple threads of people asking this question, and managing to make it work but only for pages. Making a model for my user template doesn’t seem to work, neither does using a query as the image/icon source.
I’ve tried:
- making a model for my user template, then using the field I get from the model as the query, doesn’t work. Default icon persists;
- straight up querying the
image
section in theimage:
settings, doesn’t work, panel complains: “array_merge(): Argument #3 must be of type array, string given”:
image: page.image.toFile
if I put it in a query:
, nothing happens as well, default icon persists;
- making the section into a field and querying that, also doesn’t do anything. The default icon shows up.
Is there anything I’m missing? Is it possible to make a user’s preview image a custom image? Taking a look at the source code, it seems like this should be possible but either the query just doesn’t actually work or I’m missing something. I want to be able to see the profile image of each user, as I’ll be querying users in custom blocks.
My user blueprint profile.yml
:
title: Team member
image:
query: page.image.toFile
color: "var(--color-white)"
back: "var(--color-gray-100)"
permissions:
access:
panel: false
columns:
- width: 1/3
sections:
image:
label: Profile picture
type: files
layout: cards
max: 1
multiple: false
- width: 2/3
fields:
firstName:
width: 1/2
label: First Name
type: text
lastName:
width: 1/2
label: Last name
type: text
The model profile.php
I tried:
<?php
class Profile extends Page {
public function previewImage() {
return $this->content()->get('image')->toFile() ?? $this->image();
}
}