From 0c28bbcb0986768aac41e936c575bd4b4dd73bd0 Mon Sep 17 00:00:00 2001 From: Michael <139059166+michaelptak@users.noreply.github.com> Date: Sat, 20 Sep 2025 16:02:17 -0400 Subject: [PATCH 1/2] Create Making Dynamic Dataview Queries.md --- .../Making Dynamic Dataview Queries.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md diff --git a/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md b/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md new file mode 100644 index 00000000..d4284f15 --- /dev/null +++ b/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md @@ -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. + +The code block here is the equivalent of making the query `WHERE {property} = "{value}"` + +```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" + +// Query notes where the property contains the value +const pages = dv.pages() + .where(p => p[property] && p[property].includes(value)); + +// 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); +``` From e05abebe0c2a818eb18776f3978fc58e58d6c06d Mon Sep 17 00:00:00 2001 From: Michael <139059166+michaelptak@users.noreply.github.com> Date: Sun, 21 Sep 2025 13:24:17 -0400 Subject: [PATCH 2/2] Update Making Dynamic Dataview Queries.md Hopefully much better clarity now --- .../Making Dynamic Dataview Queries.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md b/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md index d4284f15..a3df307b 100644 --- a/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md +++ b/exampleVault/Advanced Examples/Making Dynamic Dataview Queries.md @@ -1,24 +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 isn't possible with normal optionQuery. Will require adjustment based on your particular use case, but it's a place to start. -The code block here is the equivalent of making the query `WHERE {property} = "{value}"` +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 property = "categories"; // frontmatter property to filter on -const value = "character"; // value to match -// Equivalent to the Dataview query WHERE categories = "character" +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 notes where the property contains the value +// Query: WHERE categories contains "character" +// This finds all notes matching the filter criteria. const pages = dv.pages() - .where(p => p[property] && p[property].includes(value)); + .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}):${value}]\``; +const inputField = `\`INPUT[listSuggester(${options}):${fieldName}]\``; return engine.markdown.create(inputField); ```