Embed internal images in dataviewjs table from frontmatter?

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 ( myFieldType == "link" ) {
  dv.span(imgDisplay(myField))
} else if ( myFieldType == "array" ) {
  myField.forEach(i => dv.span(imgDisplay(i)))
}

function imgDisplay(imageLink) {
  return '<img src="' + app.vault.getResourcePath(dv.fileLink(imageLink.path)) + '" />'
}
```

Replace the first dv.current().myField with your field name, and hopefully that should work consistently for you as it do for me! :smiley:

4 Likes