How to create a configurable dataview search?

Hi, I want to create a dataview search, that I can easily customize or configure with a property.

So, instead of something like this:


```dataview 
table week AS Woche, title AS Titel, url, tags
from "Texte" AND #agency 
sort file desc

I would like to have something like:

---
SearchTag: agency
---

```dataview 
table week AS Woche, title AS Titel, url, tags
from "Texte" AND this.SearchTag
sort file desc

How to do that?
Thanks
Gab

I’m not sure if plain Dataview can work dynamically to get tags from the Frontmatter. But I’m sure that experts will correct me if I’m wrong :smile:

Would you dare to try using DataviewJS?

```dataviewjs
const tag = dv.current().SearchTag;

dv.table(
  ["Woche", "Titel", "URL", "Tags"],
  dv.pages('"Texte"')
    .where(p => p.tags && p.tags.some(t => t === `#${tag}` || t.startsWith(`#${tag}/`)))
    .sort(p => p.file.name, 'desc')
    .map(p => [p.week, p.title, p.url, p.tags])
);
```

Cheers, Marko :nerd_face:

1 Like

Hello.

This works in a local test vault:

```dataview 
TABLE 
week AS Woche
, title AS Titel
, url
, tags
FROM "Texte"
WHERE SearchTag = this.SearchTag
SORT file desc
```

Does it work for you?

1 Like

Tanks for your support. Unfortunately not. The entry in the “SearchTag” should search among the tags, but

```dataview 
TABLE 
week AS Woche
, title AS Titel
, url
, tags
FROM "Texte"
WHERE tag = this.SearchTag
SORT file desc
won't work.
The question for me is: how can I search among the tags?

Hello.

Is this what you need?

```dataview 
TABLE 
week AS Woche
, title AS Titel
, url
, file.etags as "tags"
FROM "Texte"
WHERE any(contains(file.tags, this.SearchTag))
SORT file desc
```

1 Like

It is, indeed. Thanks for that hint.

1 Like

Just to mention that case as well, if you want to search for a property given in another property. Aka if you wanted to search in the SearchProperty for SearchValue, you could do something like WHERE row[this.SearchProperty] = this.SearchValue.

1 Like