- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 71
Create Making Dynamic Dataview Queries.md #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|  | ||
| 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); | ||
| ``` | ||
There was a problem hiding this comment.
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