Skip to content

Commit e05abeb

Browse files
authored
Update Making Dynamic Dataview Queries.md
Hopefully much better clarity now
1 parent 0c28bbc commit e05abeb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
# 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.
32

4-
The code block here is the equivalent of making the query `WHERE {property} = "{value}"`
3+
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 aren't possible with normal optionQuery. This approach lets you filter by any frontmatter property, not just tags, to create more targeted suggestion lists.
4+
5+
Use Case: You're editing a character note and want to populate a "friends" field with only other character notes, excluding non-character content like locations, objects, etc.
56

67
```js-engine
78
const dv = engine.getPlugin('dataview').api;
89
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"
10+
const filterProperty = "categories"; // frontmatter property to filter on
11+
const filterValue = "character"; // value to match - only character notes
12+
const fieldName = "friends"; // the actual field we're populating
1213
13-
// Query notes where the property contains the value
14+
// Query: WHERE categories contains "character"
15+
// This finds all notes matching the filter criteria.
1416
const pages = dv.pages()
15-
.where(p => p[property] && p[property].includes(value));
17+
.where(p => p[filterProperty] && p[filterProperty].includes(filterValue));
1618
1719
// Turn into Meta Bind options
1820
const options = pages.map(p => `option(${p.file.name})`).join(", ");
1921
2022
// Build the Meta Bind input string
21-
const inputField = `\`INPUT[listSuggester(${options}):${value}]\``;
23+
const inputField = `\`INPUT[listSuggester(${options}):${fieldName}]\``;
2224
2325
return engine.markdown.create(inputField);
2426
```

0 commit comments

Comments
 (0)