I’m currently redesigning a website for a scientific research institute that conducts research projects in multiple different areas, produces reports on those projects once they are complete, and then occasionally has that work published in scientific journals and periodicals. The institute has a list of ‘technical team members’ (scientists) that need to relate to these projects, reports and publications in some way. More specifically, I need to be able to specify “primary authors” (for reports and publications) and “primary investigators” (for projects).
A bit about how I have it set up: I have four structures for each section: technical team, projects, reports, publications with entry types for indexes and details. I used structures so I could specify hierarchy in order to get URLs like “technical team/team member name”, “projects/project name”, etc. I used entry types so the client could edit the “overview content” on index pages (something not achievable with plain old _entry.html and index.html to my understanding). Also, this site is very big and this set up just worked for my content.
So, for example, this is how I am currently relating team members to projects. I have a ‘Featured projects’ entries field in my “Team Member” entry where the client can choose projects that the team member has been a part of. ’Featured projects’ are a little more in depth and have more information than reports and publications, but the set up is pretty much the same for reports and publications - just with fewer fields.
In templates/technical-team/_types/teamMember.html to get featured projects in a sidebar:
{% set featuredProjects = craft.entries({
section: 'projects',
type: 'featuredProject',
}).relatedTo(entry) %}
{% if featuredProjects|length %}
<div class="related-block">
<h4>FEATURED PROJECTS</h4>
{% for project in featuredProjects %}
<div class="related-item">
{% if project.projectPhoto | length %}
<img src="{{ project.projectPhoto.first.url('relatedPhoto') }}" />
{% endif %}
<div>
<a href="{{ project.url }}">{{ project.title }}</a>
<p>{{ project.intro|striptags|slice(0,120)|default('Read more') }}...</p>
</div>
</div>
{% endfor %}
</div>
{% endif %}
And then in templates/projects/_types/featuredProject.html to get related team members in a sidebar:
{% set teamMembers = craft.entries.section('technicalTeam').relatedTo(entry) %}
{% for teamMember in teamMembers %}
<div class="related-item">
<img src="{{ teamMember.bioPhoto.first.url }}" width="80" />
<div>
<a href="{{ teamMember.url }}">{{ teamMember.title }}</a>
<p>{{ teamMember.teamMemberTitle }}</p>
<a href="{{ teamMember.url }}" class="view-more">VIEW TEAM MEMBER <i class="fa fa-angle-right" aria-hidden="true"></i></a>
</div>
</div>
{% endfor %}
This code is working perfectly fine, btw.
Now for my question: what would be the best way to denote that a ‘related team member’ is the “primary investigator” (for featured projects) and the “primary author” (for reports and publications)? Side note: there can be more than one primary investigator and primary author for these projects, reports and publications.
What I would like to have would be, for example, on the report/publication “detail” it would pull the team member’s photo, name, and title (as it already does) and then, if they were the primary author, the words “primary author” would appear below their info. In the same way, on the team member detail page, it would list the reports or publications that are related to that team member and then, if they were the primary author, the words “primary author” would appear below the project info… you get the idea.
Is my only option to have them as separated entries fields? So, within a report entry I would have a “primary authors” tab with the ability to choose team members, and an “other authors” tab to choose all other team members involved? Perhaps, then I would add a <span>primary author</span>
to the loop for primary authors? I feel like there has to be some sort of set up with categories, tags, or light switch fields that I can take advantage of but since this is my first time using Craft I’m not quite sure what that is. Appreciate any help/advice anyone can give!
UPDATE:
As per @Youniteus answer below, I have added a matrix field 'authors' to the report detail entry type which has two fields: 1. an entries field where the user can select entries from the 'technical team' section and 2. a light switch field that, when ticked on, displays the words "primary author" under that team member's bio. It's working great, here is my code:
{% for block in entry.authors %}
{% set relatedTeamMembers = craft.entries.section('technicalTeam').relatedTo(block) %}
{% for entry in relatedTeamMembers %}
<div class="related-item">
<img src="{{ entry.bioPhoto.first.url }}" width="80" />
<div>
<a href="{{ entry.url }}">{{ entry.title }}</a>
<p>{{ entry.teamMemberTitle }}</p>
<a href="{{ entry.url }}" class="view-more">VIEW TEAM MEMBER <i class="fa fa-angle-right" aria-hidden="true"></i></a>
{% if block.primaryAuthor %}
<p>Primary Author</p>
{% else %}
{% endif %}
</div>
</div>
{% endfor %}
{% endfor %}
but on my team member's template (/templates/technical-team/_types/teamMember.html), I am unable to get the light switch's value. Only the related report's entry title and url. Here's how I'm getting that:
{% set relatedReports = craft.entries.section('reports').relatedTo({
targetElement: entry,
field: 'authors',
}) %}
{% for entry in relatedReports %}
<li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endfor %}
I've tried the following to get the light switch's value to no avail:
{% for block in relatedReports %}
{% if block.primaryAuthor %}
<p>Primary Author</p>
{% else %}
{% endif %}
{% endfor %}
Is it even possible to get a different field from a matrix block that contains a related entries field from that related entry? (hope that's not too confusing)