obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

dv.current() when Codeblock is transcluded

Open akashchopra opened this issue 1 year ago • 1 comments

I have a page at Scripts/Test.md that prints the current page path (excuse the ```end, as I can't persuade the markdown formatter to show nested triple backticks):

### Page path

```dataviewjs
dv.el("p", dv.current().file.link.path)
```end

When I view this page it correctly shows the path as Scripts\Test.md. However, if I transclude this into Scripts/Another Test.md as follows:

![[Test#Page path]]

it still shows Scripts\Test.md. I would expect it to show Scripts\Another Test.md, as that is the page that I'm viewing.

I couldn't find any other property on dv that gave me what I wanted - am I missing something? Alternatively, if there is another way to reuse Codeblocks across pages I'd be happy to use that instead.

Thanks for an excellent plugin!

Dataview Version

0.5.47

Obsidian Version

1.5.3

OS

Windows

akashchopra avatar Feb 12 '24 09:02 akashchopra

First of all, you need to update your dataview plugin, the current version is 0.5.64.

Secondly, to include a code segment with triple backticks, enclose the area with a quadruple backtick (aka ```` before and after the block).

I think the page is mostly rendered before embedded, so then it make sense that it still shows the Script\\Test.md as the current file. I'm not entirely sure what you want when you say reuse code blocks, but you might want to look into using dv.view() or possibly dv.execute() in combination with dv.io.load(). Both of them are capable of executing queries defined in another file, and they can be persuaded as to what is considered the current file. (Also all of the dv.query() & co functions can take a parameter to indicate that another file is to be seen as the current file.

In other words, the behaviour you're describing I wouldn't describe as a bug, it's intended behaviour to allow for the embedding to be the same as if it was seen in the original form.

holroy avatar Feb 16 '24 21:02 holroy