### Serve Documentation Locally Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Commands to install documentation dependencies and start a local MkDocs server for previewing changes. ```console foo@bar:~/obsidian-dataview$ pip3 install mkdocs mkdocs-material mkdocs-redirects foo@bar:~/obsidian-dataview$ cd docs foo@bar:~/obsidian-dataview/docs$ mkdocs serve ``` -------------------------------- ### Initialize Local Development Environment Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Commands to clone the repository, install dependencies, and start the development build process with watch mode. ```console foo@bar:~$ git clone git@github.com:blacksmithgu/obsidian-dataview.git foo@bar:~$ cd obsidian-dataview foo@bar:~/obsidian-dataview$ npm install foo@bar:~/obsidian-dataview$ npm run dev ``` -------------------------------- ### Install Dataview API Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/develop-against-dataview.md Install the Dataview API as a development dependency. ```bash npm install -D obsidian-dataview ``` ```bash npm install obsidian-dataview@0.5.64 ``` -------------------------------- ### Inline DQL Rendering Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Shows the rendered output of the inline DQL example. ```markdown Today is November 07, 2022 - 2 months, 5 days until exams! ``` -------------------------------- ### Install Build to Vault Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Manually build the plugin and install it into a specific Obsidian vault directory. ```console foo@bar:~/obsidian-dataview$ npm run build foo@bar:~/obsidian-dataview$ ./scripts/install-built path/to/your/vault ``` -------------------------------- ### Function Vectorization Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Demonstrates how functions automatically apply to individual elements when passed a list. ```js lower("YES") = "yes" lower(["YES", "NO"]) = ["yes", "no"] replace("yes", "e", "a") = "yas" replace(["yes", "ree"], "e", "a") = ["yas", "raa"] ``` -------------------------------- ### startswith(string, prefix) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Checks if a string starts with the given prefix. ```APIDOC ## startswith(string, prefix) Checks if a string starts with the given prefix. ``` -------------------------------- ### Dataview Metadata Query Example Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Demonstrates how Dataview parses different field formats, where ISO-like dates are recognized as Date types while others remain as Text. ```dataview TABLE date1, date2 WHERE file = this.file ``` -------------------------------- ### Lambda Usage Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Common patterns for using lambda functions to transform data fields or perform calculations. ```text (x) => x.field (return field of x, often used for map) (x, y) => x + y (sum x and y) (x) => 2 * x (double x) (value) => length(value) = 4 (return true if value is length 4) ``` -------------------------------- ### WHERE Clause Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Filters pages based on boolean conditions. Only pages evaluating to true are returned. ```sql LIST WHERE file.mtime >= date(today) - dur(1 day) ``` ```sql LIST FROM #projects WHERE !completed AND file.ctime <= date(today) - dur(1 month) ``` -------------------------------- ### FLATTEN Command Examples Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Expands array fields into individual rows. Useful for processing nested lists like tasks or authors. ```sql TABLE authors FROM #LiteratureNote FLATTEN authors ``` ```sql table T.text as "Task Text" from "Scratchpad" flatten file.tasks as T where T.text ``` ```sql table filter(file.tasks.text, (t) => t) as "Task Text" from "Scratchpad" where file.tasks.text ``` -------------------------------- ### String Prefix and Suffix Checks Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Functions to verify if a string starts or ends with a specific substring. ```js startswith("yes", "ye") = true startswith("path/to/something", "path/") = true startswith("yes", "no") = false ``` ```js endswith("yes", "es") = true endswith("path/to/something", "something") = true endswith("yes", "ye") = false ``` -------------------------------- ### substring(string, start, [end]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Take a slice of a string. ```APIDOC ## substring(string, start, [end]) Take a slice of a string, starting at `start` and ending at `end` (or the end of the string if unspecified). ``` -------------------------------- ### Filtering tasks by section Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Example of using meta(section).subpath to filter tasks within a specific heading. ```dataview task where meta(section).subpath = "Next Actions" ``` -------------------------------- ### typeof(any) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Get the type of any object for inspection. ```APIDOC ## typeof(any) ### Description Get the type of any object for inspection. Can be used in conjunction with other operators to change behavior based on type. ``` -------------------------------- ### Prepare for Pull Requests Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Standard workflow to verify code quality, check formatting, and run tests before submitting changes. ```console foo@bar:~$ npm run dev foo@bar:~$ npm run check-format foo@bar:~$ npm run format foo@bar:~$ npm run test ``` -------------------------------- ### dv.io.load(path, [origin-file]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Asynchronously loads the string contents of a file. ```APIDOC ## dv.io.load(path, [origin-file]) ### Description Load the contents of the given path asynchronously. ### Parameters - **path** (string/link) - Required - The path to the file. - **origin-file** (string) - Optional - The file path to resolve relative paths against. ### Returns - **string** - The contents of the file, or undefined if the file does not exist. ``` -------------------------------- ### Substring Function Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Extracts a portion of a string based on start and end indices. ```js substring("hello", 0, 2) = "he" substring("hello", 2, 4) = "ll" substring("hello", 2) = "llo" substring("hello", 0) = "hello" ``` -------------------------------- ### Compare task metadata formats Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/metadata-tasks.md Demonstrates that both shorthand and inline field syntax are treated as the same data. ```markdown - [x] Completed last Saturday ✅2021-08-22 - [x] Some Done Task [completion:: 2021-08-22] ``` -------------------------------- ### slice(array, [start, [end]]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Returns a shallow copy of a portion of an array. ```APIDOC ## slice(array, [start, [end]]) ### Description Returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included). ### Parameters - **array** (array) - Required - The array to slice. - **start** (number) - Optional - The start index. - **end** (number) - Optional - The end index. ``` -------------------------------- ### Initialize DataviewJS block Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/intro.md Create a DataviewJS block to execute JavaScript with access to the dv variable. ```dataviewjs dv.pages("#thing")... ``` -------------------------------- ### Create external links with elink() Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Constructs a link to an external URL. ```js elink("www.google.com") => link element to google.com elink("www.google.com", "Google") => link element to google.com, displays as "Google" ``` -------------------------------- ### Inline DQL in Text Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Demonstrates embedding inline queries directly within a sentence. ```markdown Today is `= date(today)` - `= [[exams]].deadline - date(today)` until exams! ``` -------------------------------- ### List files by modification time Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Displays files from the 'books' folder in a table, sorted by their last modification time. ```sql TABLE file.mtime AS "Last Modified" FROM "books" SORT file.mtime DESC ``` -------------------------------- ### Slice an array Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Returns a shallow copy of a portion of an array based on start and end indices. ```javascript slice([1, 2, 3, 4, 5], 3) = [4, 5] => All items from given position, 0 as first slice(["ant", "bison", "camel", "duck", "elephant"], 0, 2) = ["ant", "bison"] => First two items slice([1, 2, 3, 4, 5], -2) = [4, 5] => counts from the end, last two items slice(someArray) => a copy of someArray ``` -------------------------------- ### Get unique values from an array Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Creates a new array containing only the unique values from the input array. ```javascript unique([1, 3, 7, 3, 1]) => [1, 3, 7] ``` -------------------------------- ### Query recipe metadata in a table Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/example tables.md Displays cuisine and stove requirements for files in the recipes folder. ```dataview table cuisine as Cuisine, needsStove as "Needs Stove" from "recipes" ``` -------------------------------- ### Query blog metadata in a table Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/example tables.md Displays the modification time and draft status for files in the blog folder. ```dataview table mtime as Modified, draft as Draft from "blog" ``` -------------------------------- ### Apply Lambda in Dataview Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Example of using a lambda function within a map operation to filter tasks. ```dataview CALENDAR file.day FLATTEN all(map(file.tasks, (x) => x.completed)) AS "allCompleted" WHERE !allCompleted ``` -------------------------------- ### List tasks from a folder Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Retrieves all tasks associated with files in the specified directory. ```sql TASK FROM "dataview" ``` -------------------------------- ### Query using a duration literal Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Filters items where the difference between end and start times exceeds 2 days. ```dataview LIST WHERE end - start > dur(2 days) ``` -------------------------------- ### Construct links with link() Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Creates a link object from a file path, optionally with a display name. ```js link("Hello") => link to page named 'Hello' link("Hello", "Goodbye") => link to page named 'Hello', displays as 'Goodbye' ``` -------------------------------- ### Query by Links Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Selects pages based on incoming or outgoing links. Use [[]] to reference the current file. ```dataview LIST FROM [[]] ``` ```dataview LIST FROM outgoing([[Dashboard]]) ``` -------------------------------- ### Basic TABLE Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/query-types.md A minimal TABLE query that lists files. ```dataview TABLE ``` -------------------------------- ### Query by Folder Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Matches all files, sections, or tasks within a folder and its subfolders. Do not include a trailing slash in the path. ```dataview TABLE file.ctime, status FROM "projects/brainstorming" ``` -------------------------------- ### List Tasks in Projects Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Retrieves all markdown tasks from files tagged with a specific project tag. ```dataview task from #projects/active ``` -------------------------------- ### List files by date in title Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Lists files containing a date in their title, sorted chronologically using the file.day property. ```sql LIST file.day WHERE file.day SORT file.day DESC ``` -------------------------------- ### Group tasks by file Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/query-types.md Organizes incomplete tasks by their originating file link. ```dataview TASK WHERE !completed GROUP BY file.link ``` -------------------------------- ### Load custom views with dv.view Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Asynchronously loads and executes a JavaScript file from the vault. Must be awaited. ```js await dv.view("views/custom", { arg1: ..., arg2: ... }); ``` ```js await dv.view(".views/view1", { arg1: 'a', arg2: 'b' }); ``` ```js console.log(`Loading view1`); function foo(...args) { console.log('foo is called with args', ...args); } foo(input) ``` ```js await dv.view("scripts/view1", { arg1: 'a', arg2: 'b' }) ``` -------------------------------- ### Create objects with object() Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Creates a new object with alternating keys and values. Keys must be strings. ```js object() => empty object object("a", 6) => object which maps "a" to 6 object("a", 4, "c", "yes") => object which maps a to 4, and c to "yes" ``` -------------------------------- ### List games by tag Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Filters and lists files tagged with specific game genres. ```sql LIST FROM #games/mobas OR #games/crpg ``` -------------------------------- ### Query by Specific File Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Selects data from a specific file using its full path. Include the .md extension if a folder exists with the same name. ```dataview LIST WITHOUT ID next-in-line FROM "30 Hobbies/Games/Dashboard" ``` -------------------------------- ### Display game metadata in a table Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/examples.md Displays specific metadata fields from files in the 'games' folder, sorted by rating. ```sql TABLE time-played AS "Time Played", length AS "Length", rating AS "Rating" FROM "games" SORT rating DESC ``` -------------------------------- ### dv.view(path, input) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Loads and executes a custom JavaScript view file. ```APIDOC ## dv.view(path, input) ### Description Loads a JavaScript file at the given path, passing `dv` and `input` to it. This is an asynchronous function. ### Parameters - **path** (string) - Required - Path to the JS file or folder containing view.js. - **input** (any) - Required - Data to pass to the view script. ``` -------------------------------- ### Query by Tag Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/sources.md Matches all files, sections, or tasks containing the specified tag. ```dataview LIST FROM #homework ``` -------------------------------- ### dv.tryQuery(source, [file, settings]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a Dataview query, throwing an error on failure. ```APIDOC ## dv.tryQuery(source, [file, settings]) ### Description Same as dv.query, but execution failures are raised as JavaScript exceptions. ``` -------------------------------- ### link(path, [display]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Construct a link object from the given file path or name. ```APIDOC ## link(path, [display]) ### Description Construct a link object from the given file path or name. If provided with two arguments, the second argument is the display name for the link. ``` -------------------------------- ### elink(url, [display]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Construct a link to an external url. ```APIDOC ## elink(url, [display]) ### Description Construct a link to an external url (like www.google.com). If provided with two arguments, the second argument is the display name for the link. ``` -------------------------------- ### Create File Link Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Converts a path string into a Dataview Link object with optional embedding and display name. ```js dv.fileLink("2021-08-08") => link to file named "2021-08-08" dv.fileLink("book/The Raisin", true) => embed link to "The Raisin" dv.fileLink("Test", false, "Test File") => link to file "Test" with display name "Test File" ``` -------------------------------- ### object(key1, value1, ...) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Creates a new object with the given keys and values. Keys and values should alternate in the call, and keys should always be strings/text. ```APIDOC ## object(key1, value1, ...) ### Description Creates a new object with the given keys and values. Keys and values should alternate in the call, and keys should always be strings/text. ### Examples - `object() => empty object` - `object("a", 6) => object which maps "a" to 6` - `object("a", 4, "c", "yes") => object which maps a to 4, and c to "yes"` ``` -------------------------------- ### Create Section Link Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Creates a Link object pointing to a specific section within a file. ```js dv.sectionLink("Index", "Books") => [[Index#Books]] dv.sectionLink("Index", "Books", false, "My Books") => [[Index#Books|My Books]] ``` -------------------------------- ### Create a Table from Tagged Notes Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Generates a table with specific fields from notes tagged with #recipes. ```dataview TABLE recipe-type AS "type", portions, length FROM #recipes ``` -------------------------------- ### Query Games with DQL Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Displays games from a specific folder, sorted by rating with selected metadata columns. ```dataview table time-played, length, rating from "games" sort rating desc ``` -------------------------------- ### dv.io.csv(path, [origin-file]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Loads a CSV file from the specified path and returns it as a dataview array of objects. ```APIDOC ## dv.io.csv(path, [origin-file]) ### Description Loads a CSV from the given path (a link or string). Relative paths are resolved relative to the optional origin file. ### Parameters - **path** (string/link) - Required - The path to the CSV file. - **origin-file** (string) - Optional - The file path to resolve relative paths against. ### Returns - **Array** - A dataview array containing objects of CSV values, or undefined if the file does not exist. ``` -------------------------------- ### Query using a link literal Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/literals.md Sets the source of the list to a specific file link. ```dataview LIST FROM [[Study MOC]] ``` -------------------------------- ### Query Books with DataviewJS Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Uses JavaScript to group books by genre and display them in a table, sorted by rating. ```dataviewjs for (let group of dv.pages("#book").where(p => p["time-read"].year == 2021).groupBy(p => p.genre)) { dv.header(3, group.key); dv.table(["Name", "Time Read", "Rating"], group.rows .sort(k => k.rating, 'desc') .map(k => [k.file.link, k["time-read"], k.rating])) } ``` -------------------------------- ### Access Page Metadata via Links Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Demonstrates how to retrieve fields from a linked page using the index operator. ```text [[Assignment Math]].duedate ``` -------------------------------- ### Render task lists with dv.taskList Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders Task objects. By default, tasks are grouped by file unless the second argument is set to false. ```js // List all tasks from pages marked '#project' dv.taskList(dv.pages("#project").file.tasks) // List all *uncompleted* tasks from pages marked #project dv.taskList(dv.pages("#project").file.tasks .where(t => !t.completed)) // List all tasks tagged with '#tag' from pages marked #project dv.taskList(dv.pages("#project").file.tasks .where(t => t.text.includes("#tag"))) // List all tasks from pages marked '#project', without grouping. dv.taskList(dv.pages("#project").file.tasks, false) ``` -------------------------------- ### dv.queryMarkdown(source, [file], [settings]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a Dataview query and returns the result as rendered Markdown. ```APIDOC ## dv.queryMarkdown(source, [file], [settings]) ### Description Equivalent to dv.query, but returns the result as rendered Markdown. ``` -------------------------------- ### List all files in vault Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md The simplest DQL query using only the LIST query type to display all files. ```dataview LIST ``` -------------------------------- ### Create lists with list() and array() Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Creates a new list containing the provided values. array() is an alias for list(). ```js list() => empty list list(1, 2, 3) => list with 1, 2, and 3 array("a", "b", "c") => list with "a", "b", and "c" ``` -------------------------------- ### LIST Query with Additional Information Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/query-types.md Displays a specific field or a computed value alongside the file link. ```dataview LIST file.folder ``` ```dataview LIST "File Path: " + file.folder + " _(created: " + file.cday + ")_" FROM "Games" ``` -------------------------------- ### List all tasks Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Displays all tasks, regardless of completion status, found in the vault. ```dataview TASK ``` -------------------------------- ### List Notes by Status Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Lists files from the #assignments category that have an open status. ```dataview LIST FROM #assignments WHERE status = "open" ``` -------------------------------- ### Calculate product with product() Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Calculates the product of numbers in an array. Use nonnull() to filter out null values. ```js product([1,2,3]) = 6 product([]) = null product(nonnull([null, 1, 2, 4])) = 8 ``` -------------------------------- ### Retrieve page paths using dv.pagePaths Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Return a data array of file paths for pages matching the provided source. ```js dv.pagePaths("#books") => the paths of pages with tag 'books' ``` -------------------------------- ### Query Protocol Files Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Displays specific metadata from files in a directory, filtered by the existence of follow-ups and sorted by time. ```dataview TABLE file.ctime, appointment.type, appointment.time, follow-ups FROM "30 Protocols/32 Management" WHERE follow-ups SORT appointment.time ``` -------------------------------- ### string(any) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Converts any value into a reasonable string representation. ```APIDOC ## string(any) ### Description Converts any value into a "reasonable" string representation. Useful for coercing dates, durations, numbers, and so on into strings for manipulation. ``` -------------------------------- ### dv.query(source, [file, settings]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a Dataview query and returns a structured result object. ```APIDOC ## dv.query(source, [file, settings]) ### Description Execute a Dataview query and return the results as a structured object containing a type and value. ### Parameters - **source** (string) - Required - The Dataview query string. - **file** (string) - Optional - The file path to resolve the query from. - **settings** (object) - Optional - Execution settings for the query. ``` -------------------------------- ### Execute Queries Returning Markdown Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a Dataview query and returns the results rendered as Markdown. ```js await dv.queryMarkdown("LIST FROM #tag") => { successful: true, value: { "- [[Page 1]]\n- [[Page 2]]" } } ``` -------------------------------- ### Define Link Metadata Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Obsidian links are supported as metadata values. ```markdown Example:: [[A Page]] Example:: [[Some Other Page|Render Text]] ``` -------------------------------- ### dv.taskList(tasks, groupByFile) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a dataview list of Task objects. By default, tasks are grouped by their origin file unless specified otherwise. ```APIDOC ## dv.taskList(tasks, groupByFile) ### Description Render a dataview list of Task objects, as obtained by page.file.tasks. By default, this view will automatically group the tasks by their origin file. ### Parameters - **tasks** (Array) - Required - An array of Task objects. - **groupByFile** (boolean) - Optional - If false, renders tasks as a single unified list instead of grouping by file. ``` -------------------------------- ### product(array) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Calculates the product of a list of numbers. ```APIDOC ## product(array) ### Description Calculates the product of a list of numbers. Null values can be eliminated using the `nonnull` function. ### Examples `product([1, 2, 3]) = 6` ``` -------------------------------- ### SORT Command Syntax Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Orders results by one or more fields. Multiple fields resolve ties sequentially. ```sql SORT date [ASCENDING/DESCENDING/ASC/DESC] ``` ```sql SORT field1 [ASCENDING/DESCENDING/ASC/DESC], ..., fieldN [ASC/DESC] ``` -------------------------------- ### dv.header(level, text) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a header of level 1 through 6. ```APIDOC ## dv.header(level, text) ### Description Render a header of level 1 - 6 with the given text. ### Parameters - **level** (number) - Required - Header level (1-6). - **text** (string) - Required - The header text. ``` -------------------------------- ### Render Markdown List Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Converts a list of elements into a plain Markdown list string. ```js const markdown = dv.markdownList([1, 2, 3]); dv.paragraph(markdown); ``` -------------------------------- ### Load File Contents Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Asynchronously loads the string contents of a file. ```js await dv.io.load("File") => "# File\nThis is an example file..." ``` -------------------------------- ### Styling tables with CSS Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/faq.md Apply custom CSS to tables using specific classes defined in frontmatter. ```css .myTable dataview.table { background-color: green } ``` -------------------------------- ### Collect Duplicate Metadata Keys Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Using the same metadata key multiple times in a single file results in a list containing all values. ```markdown grocery:: flour [...] grocery:: soap ```dataview LIST grocery WHERE file = this.file ``` ``` -------------------------------- ### Define Metadata in Markdown Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/metadata-pages.md Demonstrates using YAML frontmatter, inline fields, and tags to define metadata within a note. ```markdown --- genre: "action" reviewed: false --- # Movie X #movies **Thoughts**:: It was decent. **Rating**:: 6 [mood:: okay] | [length:: 2 hours] ``` -------------------------------- ### DQL Table Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md A basic DQL query to display file names and ratings for books. ```dataview TABLE file.name AS "File", rating AS "Rating" FROM #book ``` -------------------------------- ### dv.list(elements) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a dataview list of elements. It accepts both vanilla arrays and dataview data arrays. ```APIDOC ## dv.list(elements) ### Description Render a dataview list of elements; accept both vanilla arrays and data arrays. ### Parameters - **elements** (Array) - Required - The array of items to display in the list. ``` -------------------------------- ### Index into Inline Field Links Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Shows how to access fields from a page referenced in an inline field rather than the literal link name. ```text Class.timetable ``` -------------------------------- ### dv.io.normalize(path, [origin-file]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Converts a relative link or path into an absolute path. ```APIDOC ## dv.io.normalize(path, [origin-file]) ### Description Convert a relative link or path into an absolute path. ### Parameters - **path** (string/link) - Required - The path to normalize. - **origin-file** (string) - Optional - The file path to resolve the link from. ``` -------------------------------- ### Create a Dataview JS block Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Use a dataviewjs-annotated codeblock to execute complex queries and render results using the dv API. ```javascript let pages = dv.pages("#books and -#books/finished").where(b => b.rating >= 7); for (let group of pages.groupBy(b => b.genre)) { dv.header(3, group.key); dv.list(group.rows.file.name); } ``` -------------------------------- ### Map paths to page objects using dv.page Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Resolve a path or link to a full page object containing all page fields. ```js dv.page("Index") => The page object for /Index dv.page("books/The Raisin.md") => The page object for /books/The Raisin.md ``` -------------------------------- ### padright(string, length, [padding]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Pads a string up to the desired length by adding padding on the right side. ```APIDOC ## padright(string, length, [padding]) Equivalent to `padleft`, but pads to the right instead. ``` -------------------------------- ### dv.fileLink(path, [embed?], [display-name]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Creates a Dataview Link object from a path. ```APIDOC ## dv.fileLink(path, [embed?], [display-name]) ### Description Converts a textual path into a Dataview Link object. ### Parameters - **path** (String) - Required - The file path. - **embed?** (Boolean) - Optional - Whether the link is embedded. - **display-name** (String) - Optional - The display name for the link. ``` -------------------------------- ### Render Markdown Task List Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Converts a collection of tasks into a plain Markdown task list string. ```js const markdown = dv.markdownTaskList(dv.pages("#project").file.tasks); dv.paragraph(markdown); ``` -------------------------------- ### dv.page(path) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Retrieves a full page object for a given path or link. ```APIDOC ## dv.page(path) ### Description Maps a path or link to a full page object containing all page fields. ### Parameters - **path** (string) - Required - The path or link to the target page. ``` -------------------------------- ### Define Basic Inline Fields Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/add-metadata.md Use the Key:: Value syntax on its own line to define metadata within the body of a Markdown file. ```markdown # Markdown Page Basic Field:: Some random Value **Bold Field**:: Nice! ``` -------------------------------- ### Execute Dataview queries with dv.execute Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a standard Dataview query string and embeds the result in the current page. ```js dv.execute("LIST FROM #tag"); dv.execute("TABLE field1, field2 FROM #thing"); ``` -------------------------------- ### dv.markdownTaskList(tasks) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a task list as a plain Markdown string. ```APIDOC ## dv.markdownTaskList(tasks) ### Description Returns a plain Markdown string representing a task list. ### Parameters - **tasks** (Array) - Required - List of task objects. ``` -------------------------------- ### Function Syntax Format Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md The standard structure for invoking a Dataview function. ```text functionname(parameter1, parameter2) ``` -------------------------------- ### Filter files by tag and field Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md Uses FROM to filter by tag and WHERE to match specific metadata field values. ```dataview LIST FROM #poems WHERE author = "Edgar Allan Poe" ``` -------------------------------- ### Complex filtering using FROM Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Combines folder restrictions, tags, and outgoing link checks in a single FROM statement. ```dataview LIST FROM (#assignment AND "30 School") OR ("30 School/32 Homeworks" AND outgoing([[School Dashboard Current To Dos]])) ``` -------------------------------- ### padleft(string, length, [padding]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Pads a string up to the desired length by adding padding on the left side. ```APIDOC ## padleft(string, length, [padding]) Pads a string up to the desired length by adding padding on the left side. ``` -------------------------------- ### Date Formatting Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Formats a date or datetime object into a string using Luxon tokens. Note that the result is a string and cannot be compared directly to date objects. ```js dateformat(file.ctime,"yyyy-MM-dd") = "2022-01-05" dateformat(file.ctime,"HH:mm:ss") = "12:18:04" dateformat(date(now),"x") = "1407287224054" dateformat(file.mtime,"ffff") = "Wednesday, August 6, 2014, 1:07 PM Eastern Daylight Time" ``` -------------------------------- ### Render headers with dv.header Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a header element with a specified level between 1 and 6. ```js dv.header(1, "Big!"); dv.header(6, "Tiny"); ``` -------------------------------- ### list(value1, value2, ...) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Creates a new list with the given values in it. `array` can be used an alias for `list`. ```APIDOC ## list(value1, value2, ...) ### Description Creates a new list with the given values in it. `array` can be used an alias for `list`. ### Examples - `list() => empty list` - `list(1, 2, 3) => list with 1, 2, and 3` - `array("a", "b", "c") => list with "a", "b", and "c"` ``` -------------------------------- ### DataviewJS Task List Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Uses the DataviewJS API to list all incomplete tasks in the vault. ```dataviewjs dv.taskList(dv.pages().file.tasks.where(t => !t.completed)); ``` -------------------------------- ### Sort Function Usage Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Returns a new list sorted in ascending order. ```text sort(list(3, 2, 1)) = list(1, 2, 3) sort(list("a", "b", "aa")) = list("a", "aa", "b") ``` -------------------------------- ### Define YAML Lists Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Lists in YAML frontmatter can be defined using square brackets or block-style syntax. ```yaml --- key3: [one, two, three] key4: - four - five - six --- ``` -------------------------------- ### Access Dataview API from other plugins Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/intro.md Retrieve the Dataview API instance from the Obsidian plugin registry. ```javascript app.plugins.plugins.dataview.api ``` -------------------------------- ### dv.date(text) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Coerces input to a luxon DateTime. ```APIDOC ## dv.date(text) ### Description Coerces text and links to luxon DateTime objects. Returns the input unchanged if it is already a DateTime. ``` -------------------------------- ### List Non-Fiction Books Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/Books.md Retrieves all files linked to the Non-Fiction category. ```dataview list from [[Non-Fiction]] ``` -------------------------------- ### List Games by Tag Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/README.md Filters and lists games based on specific tags. ```dataview list from #game/moba or #game/crpg ``` -------------------------------- ### display(value) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Converts the input into a string representation, stripping formatting like links or markdown to show the display value. ```APIDOC ## display(value) ### Description Display function converts the input into a string representation while trying to preserve the display property of data types. ``` -------------------------------- ### Create a DQL Table Query Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/dql-js-inline.md Uses the dataview codeblock type to display a table of data filtered by tag and sorted by rating. ```dataview TABLE rating AS "Rating", summary AS "Summary" FROM #games SORT rating DESC ``` -------------------------------- ### date(any) / date(text, format) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Parses a date from the provided input, optionally using a specific format. ```APIDOC ## date(any) ### Description Parses a date from the provided string, date, or link object, if possible, returning null otherwise. ## date(text, format) ### Description Parses a date from text to luxon `DateTime` with the specified format. Uses Luxon tokens. ``` -------------------------------- ### Query current file metadata in a table Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/example tables.md Retrieves comprehensive metadata fields for the current file. ```dataview TABLE file.name, file.folder, file.ctime, file.cday, file.mtime, file.mday, file.tags, file.frontmatter, file.name, file.folder, file.ctime, file.cday, file.mtime, file.mday, file.tags, file.frontmatter WHERE file = this.file ``` -------------------------------- ### dateformat(date|datetime, string) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Formats a Dataview date or datetime using Luxon formatting tokens. ```APIDOC ## dateformat(date|datetime, string) ### Description Format a Dataview date using a formatting string. Uses Luxon tokens. ``` -------------------------------- ### Filter pages by folder using FROM Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Restricts the query to pages within a specific folder and its subfolders. ```dataview LIST FROM "Books" ``` -------------------------------- ### GROUP BY Command Syntax Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/data-commands.md Groups results by a field, creating a rows array for each unique value. ```sql GROUP BY field GROUP BY (computed_field) AS name ``` -------------------------------- ### TABLE with Metadata Fields Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/query-types.md Displays specific metadata fields for files matching a tag. ```dataview TABLE started, file.folder, file.etags FROM #games ``` -------------------------------- ### TABLE with Custom Headers Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/query-types.md Uses the AS syntax to rename columns. Wrap headers with spaces in double quotes. ```dataview TABLE started, file.folder AS Path, file.etags AS "File Tags" FROM #games ``` -------------------------------- ### Display table with fields Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Generates a table showing specific fields, including aliased tags and calculated averages. ```dataview TABLE due, file.tags AS "tags", average(working-hours) ``` -------------------------------- ### Reverse Function Usage Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Returns a new list with elements in reverse order. ```text reverse(list(1, 2, 3)) = list(3, 2, 1) reverse(list("a", "b", "c")) = list("c", "b", "a") ``` -------------------------------- ### dv.execute(source) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a standard Dataview query and embeds the result. ```APIDOC ## dv.execute(source) ### Description Execute an arbitrary dataview query and embed the view into the current page. ### Parameters - **source** (string) - Required - The Dataview query string. ``` -------------------------------- ### split(string, delimiter, [limit]) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Split a string on the given delimiter string. ```APIDOC ## split(string, delimiter, [limit]) Split a string on the given delimiter string. If a third argument is provided, it limits the number of splits that occur. ``` -------------------------------- ### Render Markdown Table Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Generates a Markdown table from a list of headers and a 2D array of elements. ```js // Render a simple table of book info sorted by rating. const table = dv.markdownTable(["File", "Genre", "Time Read", "Rating"], dv.pages("#book") .sort(b => b.rating) .map(b => [b.file.link, b.genre, b["time-read"], b.rating])) dv.paragraph(table); ``` -------------------------------- ### Calculate with Dates and Durations Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/annotation/types-of-metadata.md Perform arithmetic operations between dates and durations. ```markdown departure:: 2022-10-07T15:15 length of travel:: 1 day, 3 hours **Arrival**: `= this.departure + this.length-of-travel` ``` ```markdown release-date:: 2023-02-14T12:00 `= this.release-date - date(now)` until release!! ``` -------------------------------- ### Padding Functions Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/functions.md Pads a string to a specific length using a provided character or spaces. ```js padleft("hello", 7) = " hello" padleft("yes", 5, "!") = "!!yes" ``` ```js padright("hello", 7) = "hello " padright("yes", 5, "!") = "yes!!" ``` -------------------------------- ### Execute Dataview Queries Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a Dataview query and returns a structured result object. ```javascript await dv.query("LIST FROM #tag") => { successful: true, value: { type: "list", values: [value1, value2, ...] } } await dv.query(`TABLE WITHOUT ID file.name, value FROM "path"`) => { successful: true, value: { type: "table", headers: ["file.name", "value"], values: [["A", 1], ["B", 2]] } } await dv.query("TASK WHERE due") => { successful: true, value: { type: "task", values: [task1, task2, ...] } } ``` -------------------------------- ### dv.markdownTable(headers, values) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a table as a plain Markdown string. ```APIDOC ## dv.markdownTable(headers, values) ### Description Returns a plain Markdown string representing a table with the given headers and 2D array of elements. ### Parameters - **headers** (Array) - Required - List of table headers. - **values** (Array) - Required - 2D array of elements to populate the table rows. ``` -------------------------------- ### dv.executeJs(source) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a DataviewJS query and embeds the result. ```APIDOC ## dv.executeJs(source) ### Description Execute an arbitrary DataviewJS query and embed the view into the current page. ### Parameters - **source** (string) - Required - The DataviewJS code string. ``` -------------------------------- ### DQL Expression Syntax Reference Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md A comprehensive list of valid expression types in Dataview, including literals, lambdas, references, arithmetic, and comparison operators. ```text # Literals 1 (number) true/false (boolean) "text" (text) date(2021-04-18) (date) dur(1 day) (duration) [[Link]] (link) [1, 2, 3] (list) { a: 1, b: 2 } (object) # Lambdas (x1, x2) => ... (lambda) # References field (directly refer to a field) simple-field (refer to fields with spaces/punctuation in them like "Simple Field!") a.b (if a is an object, retrieve field named 'b') a[expr] (if a is an object or array, retrieve field with name specified by expression 'expr') f(a, b, ...) (call a function called `f` on arguments a, b, ...) # Arithmetic a + b (addition) a - b (subtraction) a * b (multiplication) a / b (division) a % b (modulo / remainder of division) # Comparison a > b (check if a is greater than b) a < b (check if a is less than b) a = b (check if a equals b) a != b (check if a does not equal b) a <= b (check if a is less than or equal to b) a >= b (check if a is greater than or equal to b) # Strings a + b (string concatenation) a * num (repeat string times) # Special Operations [[Link]].value (fetch `value` from page `Link`) ``` -------------------------------- ### Render calendar view Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Displays a calendar view where pages are plotted based on their creation date. ```dataview CALENDAR file.cday ``` -------------------------------- ### Render lists with dv.list Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a list of elements from arrays or data arrays. ```js dv.list([1, 2, 3]) => list of 1, 2, 3 dv.list(dv.pages().file.name) => list of all file names dv.list(dv.pages().file.link) => list of all file links dv.list(dv.pages("#book").where(p => p.rating > 7)) => list of all books with rating greater than 7 ``` -------------------------------- ### Generate Calendar by Modification Time Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/example calendars.md Displays a calendar view based on the file modification time (mtime) for files in the 'recipes' folder. ```dataview CALENDAR file.mtime FROM "recipes" ``` -------------------------------- ### dv.markdownList(values) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a list as a plain Markdown string. ```APIDOC ## dv.markdownList(values) ### Description Returns a plain Markdown string representing a list of the given elements. ### Parameters - **values** (Array) - Required - List of elements to render. ``` -------------------------------- ### Saving calculations in metadata Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/faq.md Store calculations in metadata fields using inline DQL for reusability. ```markdown start:: 07h00m end:: 18h00m pause:: 01h30m duration:: `= this.end - this.start - this.pause` ``` -------------------------------- ### dv.el(element, text) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders arbitrary text within a specified HTML element. Supports custom classes and attributes. ```APIDOC ## dv.el(element, text) ### Description Render arbitrary text in the given html element. ### Parameters - **element** (string) - Required - The HTML tag name. - **text** (string) - Required - The content to render. - **options** (object) - Optional - An object containing `cls` (string) for CSS classes and `attr` (object) for HTML attributes. ### Example ```js dv.el("b", "This is some text", { cls: "dataview", attr: { alt: "Nice!" } }); ``` ``` -------------------------------- ### Group and sort tasks Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/queries/structure.md Retrieves incomplete tasks, sorts them, limits the count, and groups them by file link. ```dataview TASK WHERE !completed SORT created ASC LIMIT 10 GROUP BY file.link SORT rows.file.ctime ASC ``` -------------------------------- ### List Fiction Books Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/test-vault/Books.md Retrieves all files linked to the Fiction category. ```dataview list from [[Fiction]] ``` -------------------------------- ### Define Lambda Functions Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/reference/expressions.md Syntax for defining anonymous functions that accept inputs and return an expression result. ```text (arg1, arg2, arg3, ...) => ``` -------------------------------- ### Perform calculations on metadata Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md Demonstrates using functions like date() and length() to perform operations on metadata within a query. ```dataview TABLE author, date(now).year - published AS "Age in Yrs", length(file.inlinks) AS "Counts of Mentions" FROM #poems ``` -------------------------------- ### dv.table(headers, elements) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a dataview table with specified column headers and row data. ```APIDOC ## dv.table(headers, elements) ### Description Renders a dataview table. headers is an array of column headers. elements is an array of rows, where each row is an array of columns. ### Parameters - **headers** (Array) - Required - An array of strings representing column headers. - **elements** (Array) - Required - An array of rows, where each row is an array of column values. ``` -------------------------------- ### Adding CSS classes via JavaScript Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/resources/faq.md Inject a custom class into the query container using JavaScript. ```javascript dv.container.className += ' clsname' ``` -------------------------------- ### Query pages using dv.pages Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Retrieve a data array of page objects based on a source string. Folders must be double-quoted within the source string. ```js dv.pages() => all pages in your vault dv.pages("#books") => all pages with tag 'books' dv.pages('"folder"') => all pages from folder "folder" dv.pages("#yes or -#no") => all pages with tag #yes, or which DON'T have tag #no dv.pages('"folder" or #tag') => all pages with tag #tag, or from folder "folder" ``` -------------------------------- ### dv.paragraph(text) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders arbitrary text in a paragraph element. ```APIDOC ## dv.paragraph(text) ### Description Render arbitrary text in a paragraph. ``` -------------------------------- ### Display table with metadata fields Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/index.md Uses the TABLE query type to display specific fields and rename columns using the AS keyword. ```dataview TABLE author, published, file.inlinks AS "Mentions" FROM #poems ``` -------------------------------- ### Execute DataviewJS queries with dv.executeJs Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Executes a DataviewJS query string and embeds the result in the current page. ```js dv.executeJs("dv.list([1, 2, 3])"); ``` -------------------------------- ### dv.duration(text) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Coerces input to a luxon Duration. ```APIDOC ## dv.duration(text) ### Description Coerces text to a luxon Duration using Dataview duration parsing rules. ``` -------------------------------- ### Render tables with dv.table Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Renders a table using an array of headers and an array of rows. Nested arrays within rows are rendered as bullet points. ```js dv.table( ["Col1", "Col2", "Col3"], [ ["Row1", "Dummy", "Dummy"], ["Row2", ["Bullet1", "Bullet2", "Bullet3"], "Dummy"], ["Row3", "Dummy", "Dummy"] ] ); ``` ```js dv.table(["File", "Genre", "Time Read", "Rating"], dv.pages("#book") .sort(b => b.rating) .map(b => [b.file.link, b.genre, b["time-read"], b.rating])) ``` -------------------------------- ### dv.pages(source) Source: https://github.com/blacksmithgu/obsidian-dataview/blob/master/docs/docs/api/code-reference.md Queries the Dataview index for pages matching a specific source string. ```APIDOC ## dv.pages(source) ### Description Returns a data array of page objects matching the provided source query. ### Parameters - **source** (string) - Required - A query language source string (e.g., "#tag", '"folder"'). ```