Use Conditional to compare two variables if they are equal

I have a site, that offers classes. There is a page called classes where I have a table that shows all classes. All fine.
The site also has pages where I introduce the lecturers. Each lecturer has his / her own page. At the end of each lecturer-page I want to show all classes, that are held by this lecturer. I use the Plugin Var to set 2 variables.

{{ var:doz_id }} and {{ var:rel_doz_id }}

My test code loks like:

var_doz_id: {{ var:doz_id }}
{{ entries:listing folder="courses" }}
{{ var:rel_doz_id }} {{ related_doz }} {{ relate:name }} {{ numeric }} {{ /relate:name }} {{ /related_doz }} {{ /var:rel_doz_id }}
var_rel_doz_id: {{ var:rel_doz_id }}, var_doz_id: {{ var:doz_id }} <br>
{{ entries:listing }}

What does this code do?
sets the lecturer-ID for this lecturer, doesn´t change
switches to the folder courses and grabs all courses
uses the plugin var to grab the lecturer-id for the course in the actual loop. Changes with each loop
outputs both variables

This code will output this:

var_rel_doz_id: 01 02, var_doz_id: 03
var_rel_doz_id: 01 var_doz_id: 03
var_rel_doz_id: 04, var_doz_id: 03
var_rel_doz_id: 03, var_doz_id: 03
var_rel_doz_id: 03, var_doz_id: 03

So, Statamic loops and outputs the Variables correct. Nice!

What does this mean?
I have 5 courses, therefore 5 loops.
Im on the lecturer-page for the lecturer with the ID 3 ( {{ doz_id }} is always 03)
The first course is held by the lecturers 01 and 02, 2nd and 3rd course are also not of interest, but courses 4 and 5 have are held by lecturer 03, because {{rel_doz_id}} is 03.

What I want
I want Statamic to loop through the entire table and decide for each row: Is this course held by the lecturer whose page is shown.
If yes => output this row
If no => jump to the next row

I want to achive this with a an if-condition. I tried to wrap the entire table (omitted in the example code) in an if-clause, but
{{ if doz_id == rel_doz_id }}
{{ if rel_doz_id == doz_id }}

How do I set the brackets properly?

Where I also would need help Courses can be held by more than one lecturer (see course one), so the logic must be
{{doz_id}} must be part of the list of {{rel_doz_id }}
I assume, that it can be done with PHPs logical operators, but visiting the respective page left me confused.

Thanks Albert

>>>>>>> Unanswered <<<<<<<
4 Replies