Skip to content

Commit 0c28bbc

Browse files
authored
Create Making Dynamic Dataview Queries.md
1 parent 7947886 commit 0c28bbc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Making Dynamic Dataview Queries via Meta Bind
2+
A practical example showing how to dynamically populate MetaBind input fields using Dataview queries. This addresses the common use case of wanting to filter suggester options based on note properties, in ways that isn't possible with normal optionQuery. Will require adjustment based on your particular use case, but it's a place to start.
3+
4+
The code block here is the equivalent of making the query `WHERE {property} = "{value}"`
5+
6+
```js-engine
7+
const dv = engine.getPlugin('dataview').api;
8+
9+
const property = "categories"; // frontmatter property to filter on
10+
const value = "character"; // value to match
11+
// Equivalent to the Dataview query WHERE categories = "character"
12+
13+
// Query notes where the property contains the value
14+
const pages = dv.pages()
15+
.where(p => p[property] && p[property].includes(value));
16+
17+
// Turn into Meta Bind options
18+
const options = pages.map(p => `option(${p.file.name})`).join(", ");
19+
20+
// Build the Meta Bind input string
21+
const inputField = `\`INPUT[listSuggester(${options}):${value}]\``;
22+
23+
return engine.markdown.create(inputField);
24+
```

0 commit comments

Comments
 (0)