Home Creators Posts Import Register Favorites Logout
haven't archived this post yet. have a subscription? use the importer!

Content

Dataview allows you to treat your Obsidian Vault like a database allowing you to query it. This allows you to create tables that you can filter, sort and extract data from. 

Note: Copy and pasting from Patreon... and Facebook... and Discord... sometimes causes the code to break. If you are copy and pasting, pay close attention to the Syntax on the paste as often it changes. It's annoying. 

Front Matter

In order to use Dataview you will first need to understand Front Matter. Front Matter is a section at the top of your notes where you define Variables. Variables are basically little buckets where you store information. In the example below we create a bucket called name and fill it with the value Josh. 

Everything between the --- and --- is considered Front Matter. 

---

VariableName: VariableValue

name: Josh

---

Inline Expressions

Once you have Variables defined in your Front Matter; you can pull the Variable Values into your notes using Inline Expressions. 

`=this.name`

This is an inline expression that calls the name variable and returns the value. 

Example: My name is '=this.name'

Output: My name is Josh

Inline JS Expressions

Inline JS Expressions are more complex and powerful. JS stands for Jave Script. They allow you to return more advanced details such as the current date/time, the current notes name or the current notes folder. Here are some examples so you can see what's possible. 

Example1: `$= dv.current().file.mtime`

Output1: 6:30 pm - August 07, 2022

Example2: `$= dv.current().file.name`

Output2: Dataview Examples

Example3: `$= dv.current().file.path`

Output3: aTest Bed/Dataview Examples.md

Dataview Query

Dataview Queries are amazing! Imagine being able to create a table that automatically populates based on the rules you set. 

Example: Make a table of all the Level 4 Wizard Spells!

Example2: Make a table that shows all my party members!

This is all possible with Dataview Queries. 

This is an example of a Dataview Query from my personal vault. I'm asking for a table to be created with columns for Player, Class, Race and level. I'm telling it to only return Notes from within the "0. The Party/Deadly Depth Inn" folder and I'm filtering to only show notes that have Front Matter for Role where the value contains the word "Player". 

```dataview

table Player, Class, Race, level

from "0. The Party/Deadly Depth Inn"

where contains( Role, "Player")

```

Output: 

You can see the table is created, the columns are populated using the Front Matter from the Players Notes. This is what the front matter looks like in 4x of those notes. You can see the order in which the Front Matter is entered does not matter, the capitalisation however is important. You need to match exactly. 

There are so many things you could do with this. One of the things I'm using it for currently is adding a Dataview Query to notes dedicated to specific groups/guilds and returning a list of Notes that are used to describe key NPC's that belong to the group/guild. 

Here's the code for creating something similar in your notes. Please note that the right hand wiki style table is not possible out of the box, you can learn how to do that HERE.

> [!infobox]

> # Purple Dragons

> ![[Purple Dragons Coat of Arms.png|cover hsmall]]

> [[Purple Dragons Coat of Arms.png|Show To Players]]

> ###### Basic Information

> Type |  Stat |

> ---|---|

> Base of Operations | Cormyr |

> Alignment | Non-Evil, Non-Chaotic |

> ###### Relationships

> Type |  Stat |

> ---|---|

> Allegiances | Cormyr |

> ###### Key Members

> [[Add New NPC|Add New Member]]

> ```dataview

table Race, Gender

where contains( Association, "Purple Dragons") 

Dataview JS Query

This is getting very advanced now. Dataview JS Queries are advanced Jave Script queries capable of doing many many things. I can't write this code myself, I copy it off other people who are smarter than myself and manipulate it to meet my personal requirements. This however is an insanely useful query which will allow you to query the TTRPG Statblock Data and return a list of monsters!

```dataviewjs

const monstersAsDvArray = dv.array(Array.from(window.bestiary.values())).filter(m => m.name).where(m => m.name.toLowerCase().contains('goblin'))

dv.table(["Name", "HP", "AC", "CR", "Source"], monstersAsDvArray.map((monster) => [dv.fileLink(monster.name), monster.hp, monster.ac, monster.cr, monster.source]))

```

This code is currently filtering the data to only show monsters whose name contains the word 'goblin'. You can replace goblin with any name you like but note that it must be in all lowercase. The result looks like this:

This is a fantastic way to quickly do a search through your Monster Database to find something interesting for your next combat. Note that I have the Name linking to Files within my vault here. Those notes have nothing to do with the TTRPG Statblock Plugin. I have just forced the Name to become a link and it will link to any Note that has the same name. So this means I can click/hover the Goblin link because I have a separate note for the Goblin. 

Hopefully this helps and isn't too overwhelming. 

Files

Previews only

Obsidian - Getting Started with Dataview

In this video we dive into Dataview, exploring some of the basic functionality that the plugin offers. Dataview is one of those must have plugins and incredibly popular with the majority of the Obsidian community. How To Install: Obsidian / Settings / Community Plugins / Browse / Dataview / Install and Enable. 0:00 Intro 0:05 Introducing Difficulty Meter 0:33 Dataview Introduction 1:20 What Is Front Matter (YAML) 3:43 Inline Expressions 6:54 Inline JS Expressions 8:47 Dataview Queries 11:30 Example of a large query and impact on Obsidian 16:35 Dataview JS Query (Return monsters from TTRPG Statblock) 25:25 How I Use Dataview 27:29 Outro Get Obsidian - https://obsidian.md/ Official Discord - https://discord.com/invite/veuWUTm Join Facebook Community - https://www.facebook.com/groups/obsidianttrpgusers Support Me To Make More Content! - https://www.patreon.com/JPlunkett

Comments

No comments found for this post.