DataviewJS Insert Block links

Similar to this thread I’m looking for a way of inserting a block id that can reference from other notes. Currently I have certain notes that I refer to as “annotations” which are basically atomic quote notes.

An example notes looks something like this:

---
id: A-202301261028
quote: My walk... is a public one. My business is in the world; and I must mix in the assemblies of men, or quit the post which Providence seems to have assigned me"
sources:
  - { person: [[William Wilberforce]], place: [[📕 Spark]], location: test }
  - { place: [[📕 Leadership as an Identity]], location: Chapter 20 }
tags:
- servant-leadership
- faithfulness
---
\`\`\`dataviewjs 
dv.view("dv-views/annotations/v1")
\`\`\`

^d117db

This works great for the note itself, and even on my specific “book” or “person” notes I can easily list all related quotes like this:

dv.view("dv-views/book-annotations/v1")

Now the only remaining requirement/request I have is to insert a custom ^quote (see first image for reference). This way anytime I want to reference (typically with translucency) I can do something like ![[A-202301261028^quote]]

I’ve tried to so something like this in my index.js, but it did not create the same html markup as a proper block ID and ultimately it didn’t work to be recognized by my separate note.

dv.el("div", 
    dv.el("span", "^quote ", { cls: "cm-blockid", spellcheck:"false"}), 
    { cls: "cm-line"}
);

Would love any help I could get with this, curious if its possible and if not, how could I get it on the roadmap?

Sorry, I’m having trouble following exactly what you’re looking for here. Is this a Dataview feature or an Obsidian feature)

Maybe it would help to elaborate on how you imagine the following would happen:

So I think I got this to work, not sure what I was misunderstanding at the time but it actually works just as I hoped. So I have an annotation note with the following:

as part of my template, just below the dataview snippet I have a ^quote call that makes it possible for me to reference only the quote and not all of the additional notes within the file.

As you can see here this seems to work as expected so I’m happy.

2 Likes

@ryanjamurphy My apologies, what I described as working I realized is not what I was trying to do (this is what I get for going on a trip between posting and replying). As I described in my last replay, place a ^quote below my dataviewjs block works as expected, but what I wanted to accomplish was inserting that same ability within the view.js (between the quote the quote and the source detail as seen here.

Using the following code I was able to insert the text as expected but it doesn’t function as a callable section for transclution as expected.

dv.el("div", 
    dv.el("span", "^quote ", { cls: "cm-blockid", spellcheck:"false"}), 
    { cls: "cm-line"}
);

Instead I get the following error:

I have to ask again: What are you really trying to do? What’s your goal with this workflow?

@ryanjamurphy I want to be able to translucent reference (embed) a quote into a note without any of the commentary context that I might have on the note. For example every annotation note will “the quote” and below that I may have personal commentary or context that I want to maintain about the quote.

Now when I reference that from other notes I would call it by the ID with ![[A-#######]] but without creating a specific ^quote section to specify the content I want, I will be embedding the quote and any additional context I’ve added to the annotation note.

If you have a file named A-20230405 containing the following text:

> I'm great. - somebody
^quote

then you can transclude that quote by inserting ![[A-20230405#^quote]] anywhere else.

I can’t follow what you’re trying to do that doesn’t fit that use though, sorry.

@ryanjamurphy I understand that, and if I place ^quote directly in the note then of course this would work, but the issue is that what I’m placing in the note is a dataviewjs VIEW like so:

THEN, within that view.js I’m trying to place the ^quote callout with something like this at the moment:

dv.el("div", 
    dv.el("span", "^quote ", { cls: "cm-blockid", spellcheck:"false"}), 
    { cls: "cm-line"}
);

As you can see in the image below, this places the text where I want it (below the quote but above the source), but because it is within the view.js renderer it doesn’t appear to be recognized by the translucent reference (ie. [[A-202304122356#^quote]])

Hopefully this explanation helps make it a bit clearer what the issue is.

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