Images with Dataview

Good morning/afternoon/evening! I’m trying to insert an image from my attachments using the dataview plugin, but I’ve found that it only works in certain contexts.

For context, all of the relevant attachments end with -order.gif, and I’m trying to accomplish this as a part of a larger script.

Things I have tried

I’ve tried rendering with the same commands in both an inline block and a script, and only the inline block works (and even that is unreliable).

As an example:

The gif shown below the header (오늘의 한자) is rendered successfully by the inline dataviewjs block. The 軍-order.gif under the link to the page is rendered by this excerpt from the script:

dv.header(3, wrapLink(page.음훈, page.file.path));
dv.span(`![[${dv.pages("#한자").filter(p => p.숫자 == page.숫자).한자}-order.gif]]`);

Where page is the relevant daily random page.
The commented-out line is what I would like to do, while the uncommented line was my attempt to match the functioning inline block format as closely as possible. Both have the same result: 軍-order.gif, instead of the rendered gif.

Note: As I mentioned, the inline block is somewhat unreliable, too. When I first open the app, the image is rendered the same way that the script does, with the filename. After closing and reopening the preview, it renders correctly.

What I’m trying to do

I would like the image to be rendered by the script just as it is in the inline block; in the block, I can only show a particular image, but I want to use the same logic that I use in the script to retrieve a pseudo-random page.

Thanks in advance to anyone who can help me figure this out!

I solved the problem by using the obsidian API (Vault.getResourcePath) and inserting it directly with dv.container. If there’s any cleaner way to do this, please let me know! Otherwise, I no longer need help.

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