Skip to content
Open
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 isn't possible with normal optionQuery. Will require adjustment based on your particular use case, but it's a place to start.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline after the heading would be nice


The code block here is the equivalent of making the query `WHERE {property} = "{value}"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence here is confusing.


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

const property = "categories"; // frontmatter property to filter on
const value = "character"; // value to match
// Equivalent to the Dataview query WHERE categories = "character"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you say categories equals character


// Query notes where the property contains the value
const pages = dv.pages()
.where(p => p[property] && p[property].includes(value));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But here you write value in property


// 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}):${value}]\``;

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