What I’m trying to do
I want to embed a image from file automatically, but it seem it isnt working
Things I have tried
$=dv.paragraph(dv.page(dv.current().x).img)
$=dv.paragraph("![["+dv.page(dv.current().x).img+"]]")
$=dv.fileLink(dv.page(dv.current().x).img, true)
these two just show the name of the image in a paragraph
$=dv.fileLink(dv.page(dv.current().x).img)
this make a link to the image but it doesent embed
thank you for the help
holroy
January 16, 2024, 8:53am
2
This thread has some pointers to the most reliable way of embedding images.
The most reliable way I’ve found to display an image, given proper links in a field/property is like the following:
---
image: "[[myImage]]"
---
```dataviewjs
dv.span('<img src="' + app.vault.getResourcePath(dv.fileLink( dv.current().image.path )) + '" />'))
```
You could also construct such monstrosities as the following if you don’t know whether your myField is one link or an array of links:
```dataviewjs
const myField = dv.current().myField
const myFieldType = dv.func.typeof(myField)
if…
1 Like
oh thanks, i used you code to do
$=dv.span('<img src="' + app.vault.getResourcePath(dv.fileLink(dv.page(dv.current().x).img)) + '" />')
but i couldnt find a way to resize the image, do you know how can i do it?
holroy
January 16, 2024, 11:19am
4
At this point it’s an ordinary <img>
so you could use attributes and styles, and what ever you like.
1 Like
system
Closed
January 23, 2024, 12:24pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.