Skip to content

How to setup Dataview views

Posted on:September 6, 2023

Short guide on how to setup views for the Dataview Obsidian plugin.

Official documentation for views can be found here.

Creating the view

  1. Create a folder where you’ll put all of your Dataview views.
    • This must be a folder in your vault that is visible to Obsidian. It can’t be in a hidden folder.
  2. Create a file with the .js extension and paste the contents of the “view” code into it.
    • You likely will not be able to do this within Obsidian. You can use your OS file explorer or an IDE like VS Code.
    • This file should go in the folder you created in the previous step.

Using the view in a markdown file

You can reference the view in a DataviewJS codeblock. You pass it the path to your view and any arguments you want to pass to the view. For example, if you created a view at the path “Meta/Dataview Views/my-view.js”, then to reference the view in a markdown file, you’d do the following:

dv.view("Meta/Dataview Views/my-view")

To pass an argument to the view, you can pass it as the second argument. You can pass whatever you want. Here’s an example of passing a string:

dv.view("Meta/Dataview Views/my-view", "Hello world")

And in the view, accessing it through the input variable:

dv.header(6, input);

And here’s an example of passing an object:

dv.view("Meta/Dataview Views/my-view", { message: "Hello world" })
dv.header(6, input.message);