Hello.
I have a structure field setup on the site level for ‘team_members’. This contains a person’s name, job title and photo ( file field ).
I’ve got a blog setup, with a page template called article.
In the blog article the user can select a team member in a select field, blueprint below:
author:
label: Author
type: select
options:
type: query
query: site.team_members.toStructure
text: "{{ item.name }}"
value: "{{ item.name }}"
I’m trying to create a model, that adds a team_member_image() method. But whenever I call $article->team_member_image()->toFile() on the page template, I get an error of ‘Call to a member function toFile() on string’. If I don’t call toFile() an img tag is echo’d to the page.
If I print_r what I’m returning from the model, in the article.php model file, it’s a Kirby\Content\Field Object.
Model code is below.
<?php
use Kirby\Cms\Page;
class ArticlePage extends Page
{
public function team_member_image(): string
{
$page_id = $this->id();
$team_member_image = false;
if ($this->author()->isNotEmpty()) {
// Get all team members
$team_members = kirby()->site()->team_members()->toStructure();
foreach ($team_members as $member) {
// Does this match our article author?
if ( $member->name() == $this->author()->value() ) {
return $member->photo();
}
}
}
return $team_member_image;
}
}
What am I missing, or is there a better way to do this?
Thanks for the help
Ian.