Here's a full explanation of my use case:
I have Statamic membership configured for employees in my company. Being a university, their most common classification
is either Faculty or Staff. Each employee has a primary appointment in a unit
(which you can think of like a department in a private company - also, you will also see a field called program
below which is practically synonymous with a unit for the purpose of this explanation).
In addition the primary appointment, an employee may be affiliated with two or three other units, so I put all their affiliations
into a grid field.
Here is a relevant sample YAML snippet from a member file:
affiliations:
-
job_title: Director
unit: Speech and Hearing Clinic
program: ""
classification: Staff
-
job_title: Adjunct Professor
unit: Department of Educational Psychology
program: School Psychology
classification: Adjunct Faculty
-
job_title: Directorly Professor
unit: Department of Communication Sciences and Special Education
program: Special Education
classification: Faculty
Within the template, I need to setup two sections on a page... one for "Faculty" and one for "Staff" and list all the members affiliated with the current unit, which I'm identifying from the URL. Here's a snippet of the first section, for members classified as Faculty:
{{ get_content from="/directory/{ segment_3 }/{ segment_4 }" }}
<h2 id="faculty">Faculty</h2>
{{ member:listing sort_by="username" conditions="affiliations" }}
{{ if no_results }}
<p>No matching profiles.</p>
{{ else }}
{{ if first }}<p>{{ total_results }} total results. Check the current title: <strong>{{ title }}</strong></p>{{ endif }}
<p><small><em>Checking affiliations for <strong>{{ username }}</strong>...</em></small></p>
{{ affiliations }}
{{ if classification=="Faculty" }}
{{ if unit=="{ title }" || program=="{ title }" }}
<figure>
<div class="portrait">
{{ get_files in="/assets/img/directory" match="{ username }.jpg" }}
<img src="{{ file }}" alt="Portrait of {{ first_name }} {{ last_name }}" />
{{ /get_files }}
</div>
<figcaption>
<h3 class="name"><a href="/directory/profiles/{{ username }}">{{ first_name }} {{ last_name }}</a></h3>
<div class="title">
<em>{{ job_title }}</em>
<br>{{ unit }}
<br>{{ program }}
<br>{{ classification }}
</div>
</figcaption>
</figure>
{{ else }}
<p><small><em>if statement doesn't match: unit=="{ title }" || program=="{ title }"
<br>Checking title: [{{ title }}]
<br>Checking unit: [{{ unit }}]
<br>Checking prg: [{{ program }}]</em></small>
</p>
{{ endif }}
{{ else }}
<p><small><em>if statement doesn't match: classification=="Faculty"
<br>Checking classification: [{{ classification }}]</em></small>
</p>
{{ endif }}
{{ /affiliations }}
{{ endif }}
{{ /member:listing }}
{{ /get_content }}
Here is my output:
Of the 6 members pictured, only 2 actually meet all the criteria (aagrooms and acohen) and should display the figure
block which includes their picture and contact information. The breakdown is happening when I reference { title }
in an IF statement in a grid in a {{ member:listing }}
.
edit: Curtis Blackwell suggests below using the var
add-on to give the title
variable a different name. I tried it but got a PHP syntax error, so I stopped trying it.
Any other suggestions?