Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Making Dynamic Dataview Queries via Meta Bind

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.

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.

```js-engine
const dv = engine.getPlugin('dataview').api;

const filterProperty = "categories"; // frontmatter property to filter on
const filterValue = "character"; // value to match - only character notes
const fieldName = "friends"; // the actual field we're populating

// Query: WHERE categories contains "character"
// This finds all notes matching the filter criteria.
const pages = dv.pages()
.where(p => p[filterProperty] && p[filterProperty].includes(filterValue));

// Turn into Meta Bind options
const options = pages.map(p => `option(${p.file.name})`).join(", ");

// Build the Meta Bind input string
const inputField = `\`INPUT[listSuggester(${options}):${fieldName}]\``;

return engine.markdown.create(inputField);
```