Dataview: Return backlinks present in line starting with given string

I have organised my notes into a somewhat hierarchical structure using links. Most of my notes contain the following line, with the appropriate replacement:

Topics: [[topic-note-1]] [[topic-note-2]]

For example, in my note for New York I have the line:

Topics: [[City]] [[USA]]

What I want to obtain is to show a table in the City and USA notes that displays a list of sub-topics, i.e. the names of the notes (e.g. New York) that contain backlinks to the note the table is in. However, I only want to display those notes in which the backlink is in the line starting with “Topics:” and ignore notes with backlinks present elsewhere in the note.

Additionally, though not essential, it would be great to have a second column in the table which includes the number of sub-sub-topics each sub-topic has, i.e. the number of backlinks (filtered in the same way) that the sub-topic has.

I have been able to obtain this table without the appropriate filtering for backlinks in the “Topics:” line with the following query:

TABLE WITHOUT ID file.link as Subtopics, length(file.inlinks) as "\# Subsubtopics"
FROM [[#]]
SORT length(file.inlinks) DESC

I have also read a few older posts that Dataview can’t read the contents of a note, so Dataviewjs would have to be used. Not sure if this is still the case.

I am unfamiliar with Dataviewjs and JavaScript in general so any help or pointers to useful documentation would be greatly appreciated (the documentation i found wasn’t very helpful).

You don’t say whether this is written in your frontmatter/property section, or within the body of your note. In either case some slight changes are needed to make it easier to process using something like Dataview.

Consider the following example:

---
yaml-topics: 
- "[[City]]"
- "[[USA]]"
---

body-topics:: [[City]], [[USA]]

Using this syntax you’d be able to process the information using array indexing, and you could do some filtering based on the index of the link in the list. It’ll not be easy, but let us start with where and how do you define these topics. And another important question is it likely that you could have multiple topics defined in your file (this applies in the case of defining the topics in the body).

Thanks for your reply @holroy.

I am writing the topics at the top of the body of the note, using the following template:

Topics:
Reference:
Type: 

---

Created: `=this.file.cday`
Modified: `=this.file.mday`

---

# `=this.file.name`

I’m not familiar with body-topics::, is it a special keyword necessary to

as you suggest?

Or would my Topics: “keyword” do the trick?

It would be great to be able to keep using the template I have at the moment, as my workflow includes a Python script built around it that automatically organises my vault, highlights empty notes, etc.

Thanks again.