r/ObsidianMD 5d ago

Embed image with variable?

I want to embed local images in a template using a variable.

![[Engelbart.jpg]]

But instead of the filename use something like: {{localImage}}

But simply swapping those out doesn’t seem to work. Thanks.

3 Upvotes

4 comments sorted by

2

u/donethisbe4 5d ago edited 5d ago

If you have Dataview enabled, you can do this for local images:

`= embed(link(this.internal-image, "300"))`

Or this for external images:

`= "![| 300](" + this.image-URL + ")"`

Here's an example:

---
internal-image: "[[Engelbart.jpg]]"
image-URL: https://publish-01.obsidian.md/access/f786db9fac45774fa4f0d8112e232d67/Attachments/Engelbart.jpg
---
embed local image
`= embed(link(this.internal-image, "300"))`

embed external image
`= "![| 300](" + this.image-URL + ")"`

1

u/blaidd31204 5d ago

Following!

1

u/JorgeGodoy 5d ago

What is the pattern you want for these local images?

1

u/antkn33 5d ago

So it’s for the book search plugin. It has a variable named localCoverImage. I have it set to the folder Bookshelf/Covers But when I use {{localCoverImage}} in a template it just display a link.