Find Pages linked to current page that have a tag

When visiting a page that represents a company or group, I would like to list the people that reference it.

The out of the box “Linked Mentions.md” will return all mentions, which will include the pages that are people.

However, I would like to refine that query in a new template that will only return the pages that are people (tags = “type_person”)

What am I a doing wrong?

{{#let @linkedMentions = {link where toPage = @page.name and page != @page.name and page.tags = "type_person" order by page}}}
{{#if @linkedMentions}}
# People
{{#each @linkedMentions}}
* [[{{ref}}]]
{{/each}}
{{/if}}
{{/let}}

page is this context is a string, it’s the name of the page. It’s not an object you can pull additional properties out of (like page.tags).

This is a classic case of something that would require a join, which is not something SilverBullet supports. Hypothetically you could attempt to do a page lookup for every link, where you would somehow look up every page up by name, and then look at the tags defined in there, but this would be very costly. That said, let me include a space script that allows you to do this:

```space-script
silverbullet.registerFunction({name: "findPageByName"}, async (name) => {
  const results = await system.invokeFunction("index.queryObjects", "page", {filter: ["=", ["attr", "name"], ["string", name]]});
  if(results.length === 1) {
    return results[0];
  } else {
    return null;
  }
});
```

You can then probably use it with findPageByName(page).tags = "type_person"

Again, this is very expensive, so if you have a lot of matches, this may simply hang. Use at your own risk :slight_smile: