My dataviewjs and dataview blocks are not rendering/showing up suddenly

Things I have tried

My apologies for anyone who saw my first post, the formatting was impossible to follow, and complete hodge podge and i’ve removed that post and fixed it with this one. Thanks for anyone who can help!

I’ve tried changing all the settings for turning off and on the javascript settings for inline and block within the dataview plugin. I’ve also tried updating - i did find an update and installed it. I tried turning off all other plugins, so see if another one was causing the issue. I’ve tried switching between reading view, source view, and live preview (i mostly work in live preview) but none of these settings are changing what i’m seeing.

What I’m trying to do

I have several Dataviewjs code blocks throughout my notes, and they were working fine today until suddenly they stopped working, like the graphs either don’t throw an error and completely disappear, or they throw an error I can’t make sense of.

I remember I was updating my yaml sections in several notes because I accidentally put the three ticks and “yaml” at the top of every file and was wondering why my aliases weren’t working. So i was removing those from my templates and existing notes one by one to get the aliases working again when I noticed my dataviewjs blocks were broken.

Here’s one example of what’s going wrong:

Within my “people” notes, I have dataviewjs blocks that are pulling in all the meetings that i’ve had with that person, which I got from @dannb here Dann Berg's People Template for Obsidian. Uses Dataview & Templater plugins. Should be saved as a Markdown file in Obsidian. Full blog post coming soon on dannb.org · GitHub, and had to rejig it a bit to get it to work the way I was hoping.

Here is my dataviewjs block:

await dv.view("meta/views/meetings_for_person", {filename: dv.current().file.name});

Here’s what’s happening in Live Preview:
04-01-2023-03-58-18

It’s just not showing up.

Here’s another example of what’s going wrong:

I also have another section of dataviewjs code blocks that pulls in interesting details I’ve written during meetings using FirstnameLastname:: syntax, which used to be working earlier today. I got this from this forum topic: Aggregating personal details from meeting notes into Person pages

It used to be working flawlessly, and here is the dataviewjs code block:

const personString = dv.current().file.name.split(" ").join("");
dv.list(dv.pages("").where(p => p[personString])[personString]);

and this in Live Preview mode:
04-01-2023-04-01-24

Here’s a third example of what’s going wrong:

What’s weird is not ALL of my dataview blocks are broken, as this one is working fine:
In Source Mode:

const today = dv.func.date('today');
const birthday = dv.current().birthday;
 
function difference(d1, d2) {
  var m = moment(d1);
  var years = m.diff(d2, 'years');
  m.add(-years, 'years');
  var months = m.diff(d2, 'months');
  m.add(-months, 'months');
  var days = m.diff(d2, 'days');
 
  return {years: years, months: months, days: days};
}
 
y = difference(Date.parse(today), Date.parse(birthday));
dv.span(y)

In Preview Mode:
04-01-2023-04-03-57
But interestingly, not in Reading Mode:
04-01-2023-04-04-27

Here’s a fourth example that’s going wrong:

The last thing that’s not working, is my dataview block in my Meetings Notes.
it lists details of the attendees, pulled from their linked People Note. I know SOME of it is working, because when I remove all the attendees from the attendees:: area of the note, it correctly displays “No people”.

But when I link two names like attendees:: [[This Person]], [[That Person]] (which used to work), i get NOTHING in live preview or reading mode, it just looks invisible.

I would post more images, but as a new user here i’m limited to 5 embedded images.

At this point, I’m really not sure why it suddenly stopped working. If it helps, here are my two templates I used for People, and Meetings:

My People Template:

<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Person's Name");
    await tp.file.rename(`${title}`);
  } 
  await tp.file.move("/people/" + `${title}`);
  tR += "---"
%>
created: <% tp.file.creation_date() %>
aliases: []
---
contact-info:
- company: <% tp.file.cursor() %>
- address: 
- title: 
- phone:
- email: 
- birthday: 
- deathday:
age::

\```dataviewjs
const today = dv.func.date('today');
const birthday = dv.current().birthday;
 
function difference(d1, d2) {
  var m = moment(d1);
  var years = m.diff(d2, 'years');
  m.add(-years, 'years');
  var months = m.diff(d2, 'months');
  m.add(-months, 'months');
  var days = m.diff(d2, 'days');
 
  return {years: years, months: months, days: days};
}

y = difference(Date.parse(today), Date.parse(birthday));
dv.span(y)
\```
---

# <%* tR += `${title}` %>
---
date:: [[<% tp.date.now("YYYY-MM-DD") %>]]
type:: #person
tags:: 
links::  [[🙍‍♂️People MOC]]

---
## Notes

- 

## Personal Notes: 
\```dataviewjs
const personString = dv.current().file.name.split(" ").join("");
dv.list(dv.pages("").where(p => p[personString])[personString])
\```

---
## Meetings

\```dataviewjs
await dv.view("meta/views/meetings_for_person", {filename: dv.current().file.name})
\```


___
## Interesting details:
Notable Details:: 
Hobbies:: 
Love Language:: 

___
## Relations
Spouse:: 
Children:: 
Colleagues:: 

---
This page was last edited on: **`$= dv.current().file.mtime`**

My Meetings Template:

<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Meeting Description");
    await tp.file.rename(`${title}`);
  } 
  await tp.file.move("/notes/meetings/" + `${title}`);
  tR += "---"
%>
created: <% tp.file.creation_date() %>
aliases: []
---

# <%* tR += tp.date.now("YYYY-MM-DD") + " " + `${title}` %>
---
date:: [[<% tp.date.now("YYYY-MM-DD") %>]]
type:: #note/meeting 
attendees:: <% tp.file.cursor() %>
summary:: 
tags::
links:: [[🗣 Meetings MOC]],

---
## agenda / questions
- 

## notes / minutes
- 

## action items (put into TickTick)
- [ ] 

## meeting recording link


## attendee details:
\```dataviewjs
let facts = ["Children", "Spouse", "Notable Details", "Love Language", "Hobbies"]
displayAttendeeFacts(facts)

function displayAttendeeFacts(facts) {
	let people = getLinkedPeople()   

	let tableColumns = ["person"].concat(facts)
	let tableDataFunction = (page) => {
		let personColumn = [dv.fileLink(page.file.name)]
		let factColumns = facts.map(fact => page[fact])
		return personColumn.concat(factColumns)
	}
	
	if (people.length > 0) {
		dv.table(tableColumns, people.map(tableDataFunction).sort(page => page.file))
	} else {
		dv.paragraph("No people.")
	}
}

function getLinkedPeople() { 
	// Get filenames from outgoing links
	let outlinks = dv.current().file.outlinks || []
	let attendees = outlinks.map((link) => link.path.match(/.*\/(.*)\.md/)[1])

	// Retrieve 'people notes' with the same names as outgoing links
	let linkedPeople = []; 
	if (attendees.length > 0) {
		linkedPeople = dv.pages('#person')
			.filter(page => {
				let fileName = page.file.name
				let isNotATemplate = !fileName.contains("Template")
				let isAnAttendee = attendees.includes(fileName)
				return isNotATemplate && isAnAttendee
			})
	}

	return linkedPeople 
}
\```

---
This page was last edited on: **`$= dv.current().file.mtime`**

i’ve tried to be as thorough as i can so that someone has the information to understand what’s going on, sorry if I was incredibly verbose haha.

I have a very similar issues lately. Here’s an example, I have a simple dataviewjs block like this:

When in live preview mode it works exactly as expected as seen here:

But then when I switch to the reading view I get this translation:

I’m using “Things” theme but just to confirm I switch to the default theme and got the same results

I’m guessing it’s the dot in your block type. Instead of:

```dataview.js

it should be

```dataviewjs

Was about to say good catch thinking I missed something so simple, but then I tried it and now I’ve got this error in every mode

Oh – sorry, I didn’t look closely enough at your query. You have a Dataview Query Language (DQL) query inside of a DataviewJS block, which won’t work. Try changing the type to “dataview”, as in:

```dataview

Perhaps that will give you a different, more helpful error. :sweat_smile:

1 Like

Could you provide even some more information? :smiley:

In your people template you list a lot of fields with just a single colon, and you seem to be using an object notification which is mostly used within the frontmatter, (and doesn’t work the same way in body text).

So seeing an example of an actual people mote and/or meeting note would be useful. I’m also somewhat unsure on that usage of \``` in your template, and which effect that will have in the actual notes, so be sure to include that part as well.

To ensure proper formatting of all of this, please see the bonus tip below:

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks) is properly shown.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.