I'm trying to create a template for an MOC which lists all incoming links by category based on if those Notes have a link to another group of notes, which are differentiated by a tag, in dataview

What I’m trying to do

For that question to make any sense here is how my notes are set up.
The organization I have is the top level with MOCs which I have three types Disciplines(and Subdisciplines), Topics, and Persons, these are all tagged as MOCs and with their types. All my notes link up to these in some way.
Here’s a drawing to illustrate (I apologize in advance for my handwriting and drawing abilities): https://imgur.com/twEIJMo

What I’m trying to do is create a template for the Topics MOCs. Which lists all the incoming links by Disciplines.

For example in the picture. If I create the note “Mental Health” it should create two lists, One for all the notes linking to "Mental Health and “Psychology”, and a second for all the notes linking to “Mental Health” and “Sociology”.

I only really use tags for meta information, such as status, type of notes esc. So all other relations are made through links.

Things I have tried

As I have basically zero programming experience I really didn’t know how to approach this one. I have gotten most of the single steps working but they require manual intervention at every step.

You can put a dataview query in your MOC template. This, however, requires (at least I can’t think of an alternative solution at the moment) that you add frontmatters to your files.

In your MOCs (here for the “Mental Health” MOC), put the following frontmatter at the beginning of your file:

---
Discipline:
  - Sociology
  - Psychology
---

(There have to be two spaces in front of the dash!)

In every file that links to your “Sociology” note, add the following frontmatter:

---
Discipline:
  - Sociology
---

In every file that links to your “Psychology” note, add the following frontmatter:

---
Discipline:
  - Psychology
---

Now, add the following dataview query to your MOC template:

TABLE WITHOUT ID Discipline, map(rows, (r) => "* " + r.file.link) AS Notes
FROM [[]]
WHERE file.path !=this.file.path
FLATTEN Discipline
GROUP BY Discipline
WHERE any(contains(Discipline,this.Discipline))

This should result in your desired outcome.

After reading your post again, I realized that I am not completely sure if you want to list all notes that both link to “Mental Health” and “Sociology” (or “Psychology”) or if you want to list the notes that link to “Mental Health” and are tagged with “Sociology”.

If the latter is the case, the procedure would be even a bit easier.

In this case you only have to tag your “Mental Health” note with #sociology and #psychology (but only with these two tags) and add the following dataview query to your MOC template (you don’t need the frontmatters anymore):

TABLE WITHOUT ID Discipline, map(rows, (r) => "* " + r.file.link) AS Notes
FROM [[]]
WHERE file.path !=this.file.path
FLATTEN file.tags AS Discipline
GROUP BY Discipline
WHERE contains(this.file.tags, Discipline)

Thanks a lot this worked perfectly!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.