Using metadata of pictures inside the note

What I’m trying to do

I’m trying to write a template for book review, i’m using frontmatter for storing metadata that I use in the body of the note. Everything works but the metadata containing the cover of the book is not working inside the body of the note

Things I have tried

the frontametter section is:

---
Title: Bacci Pagano. Una storia da Carruggi
Author: Bruno Morchio
Rating: ⭐⭐⭐⭐
Genre: Giallo
Cover: ![[bacci_pagano_una_storia_da_carruggi.jpg]]
Quotes:
---

and the note is:

| <div style="width:100px"></div> | |
| --------------------------------------- | ------------------------------------- |
| Title:        | `=this.Title` |
| Author:        | `=this.Author` |
| Cover:        | `=this.Cover` |
| Genre:        | `=this.Genre` |
| Status:  | Letto |

My issue is that the cover doesn’t display the picture but the text itself.

bacci_pagano_una_storia_da_carruggi.jpg is a valid jpg stored locally and if I write in the note ![[bacci_pagano_una_storia_da_carruggi.jpg]] the cover display as an image

I’m new to Obsidian and this is my first post here…thanks everyone for this useful forum!

regards
Paolo

Try either adding quotes:

Cover: "![[bacci_pagano_una_storia_da_carruggi.jpg]]"

or moving the embed syntax to the body of the note (tho this might not be great if you sometimes have no image):

---
Cover: bacci_pagano_una_storia_da_carruggi.jpg
---

%% Stuff omitted %%
Cover:        | ![[`=this.Cover`]]

Hi, thanks for your reply.
Adding quotes doesn’t help (both double " and single ')

Trying the second option lead to a different result because while rendering the markdown a new message says: =this.Cover is not created yet. Click to create

Thanks
Paolo

I don’t really know Templater (or whatever you’re using here), but it would help if you post the markup that results from the metadata and template you show in your original post.

Hi, i’m not using Templater or other plugins, maybe what i’m trying to do is not provided by core Obsidian and I have to install Templater? It’s strange because it works for strings but not for images.

My markdown is:

---
Title: Bacci Pagano. Una storia da Carruggi
Author: Bruno Morchio
Rating: ⭐⭐⭐⭐
Genre: Giallo
Cover: ![[bacci_pagano_una_storia_da_carruggi.jpg]]
Quotes:
---

| <div style="width:100px"></div> | |
| --------------------------------------- | ------------------------------------- |
| Title:        | `=this.Title` |
| Author:        | `=this.Author` |
| Cover:        | `=this.Cover` |
| Genre:        | `=this.Genre` |
| Status:  | Letto - aiuto |
| Summary:        | Mentre indaga su un caso di guerra commerciale e di riciclaggio di denaro sporco, l'investigatore privato Bacci Pagano viene assoldato da un vecchio amico no global, per scoprire chi ha rubato la carabina con cui qualcuno vuole uccidere il Presidente del Consiglio in visita a Genova |
| Rating:        | ⭐⭐⭐⭐ |
| | |

![[bacci_pagano_una_storia_da_carruggi.jpg]]

and the render is:

as You can see the third row of the table display a string instead of the cover but after the table the same syntax display the right cover.

Thanks

Any use with this? The first will work with the Dataview plugin.

---
Title: Bacci Pagano. Una storia da Carruggi
Author: Bruno Morchio
Rating: ⭐⭐⭐⭐
Genre: Giallo
Cover: "![[bacci_pagano_una_storia_da_carruggi.jpg]]"
Cover2: https://books.google.es/books/content?id=KMi9oQEACAAJ&printsec=frontcover&img=1&zoom=1&imgtk=AFLRE70TxyIDORnS3fxqUJH1dtqiLj87W7wphRSpffUURW950Sphu5A1rRMlJQPZBI1QtCR_B9XdMcPRkxYoqQ3FRsgaICJ-_oe5fBsrxlWr-hnZMbboTAHuZCK-7Tg4hvWzFN2zJGQv
Quotes:
Status: Letto
---
# Cover
```dataview
TABLE WITHOUT ID
Cover
WHERE file.name = this.file.name
```
***
# Cover 2
`="![image|100](" + this.Cover2 + ")"`

| <div style="width:100px"></div> | |
| - | - |
| Title: | `=this.Title` |
| Author:| `=this.Author` |
| Genre: | `=this.Genre` |
| Status: | `=this.Status` |
| Summary: | Mentre indaga su un caso di guerra commerciale e di riciclaggio di denaro sporco, l'investigatore privato Bacci Pagano viene assoldato da un vecchio amico no global, per scoprire chi ha rubato la carabina con cui qualcuno vuole uccidere il Presidente del Consiglio in visita a Genova |

Hi eightning, thanks for your support.
Yes using dataview I can get the picture but to install a so much useful e full of features plugin only to display an image it seems to much to me, I was wondering why using the plain & simple approach the image doesn’t show up.
Also it’s strange that the second approach You wrote with Cover2 doesn’t work but I see it’s working in your screenshot and I just copy/pasted your code…this is really hard to explain for me.

1 Like

ok, I found that also the second approach is working but only for online images, not for local stored images. It seems local images are managed in a different way, with different syntax and something goes wrong using ![[local_image.jpg]] as metadata.
Thanks

1 Like

Here is a link to a thread stating that images using DQL inline queries, aka `= … ` doesn’t really work for the time being:

The alternative from that thread is the dataview code block shown by @anon63144152 above, and it’s not very convenient to use within a table.

The only options I see you’re left with currently are either hard-coding the image directly into the table, or possibly to use some variant using the tag directly.

One version of the latter, which is also a little long for use within a table is the following:

---
cover: full/path/toImage.jpg
---
`$= dv.container = '<img src="' + app.vault.getResourcePath( dv.fileLink(dv.current().cover) ) + '" />' `

That kludge does work on the desktop on mac, but I’m not sure if it works on iPad / android / Windows / Linux… Theoretically, it should work, but theory is not everything in this game…

With that being said, one variant could be to do a dv.view() in some variant. Then you should be able to do `$= dv.view(“js/img”, dv.current().cover) ` within your table, and have it properly showing.

Would that be an interesting option?

Some prerequisites to get started with dv.view() scripts

To do dv.view() scripts you need to be able to create pure text files ending with .js, and edit these in an external editor (that is unless you’ve got some plugins related to plaintext editing of files). A good alternative for at least Mac and Windows is VS Code.

It’s usually a good thing to keep these scripts within a dedicated folder in your vault, so for the rest of this post I’ll assume you’ll use vault/_js/ for all these script files, where vault is the base path of your vault. If you change this to something else, you’ll also need to change all references to “_js/” to match that new folder.

The simple variant

The most barebone variant of such a script for displaying image would be to have the following in a _js/bareImg.js:

const basePath = `file://${this.app.vault.adapter.basePath}/`
const imgFile = dv.current()[ input ]
return `<img src="${basePath}${imgFile}" />`

Usage: `dv.view(“_js/bareImg”, “cover”) `), where cover refers to a field in the current file holding the full path of the image file, i.e. some/folder/myImage.png

This doesn’t allow for any styling beside what you enter directly into the <img> tag in the script itself.

Advantage of this variant is that it’s the shortest footprint related to what you need to type within your table. One disadvantage is that it only uses fields defined within the current file.

With some styling options

Another slightly more advanced version, which I’m using in one of my vaults is this one (which I’ve stored as _js/img.js):

const basePath = `file://${this.app.vault.adapter.basePath}/`
const imgFile = input.src
const style = input.style

return `<img src="${basePath}${imgFile}" style="${style}"  />`

Usage: `$= dv.view(“_js/img”, {src: “some/image.png”, style:“width: 200px; height: 50px; float: right” }) `

This sets all of those html styles directly for the image, and allows for me to place and size (and whatever else is possible through the style-attribute) for the image. The usage pattern is a little larger though, and I’m happy with defining the source directly in the call, so it’s not as easy to use in combination with an inline field (unless you modify the script a bit to match the first variant for the src attribute).


Disclaimer: I’ve not tested this on the various platforms, and it might need adjusting especially for iOS or android, possibly.

Apologies for the late reply … think Holroy has answered all the points.

Welcome to the forum.

One point which I hadn’t cover was this statement. By doing `= this.cover` you’re already utilising dataview. Metadata or inline fields, depend on upon dataview for retrieval in most (if not all) cases.

The plain and simple approach is just to do ![[someImage.png]]

1 Like

thanks everyone for your support, very helpful, I will choose the simplest I suppose…hardcoding for the moment :slight_smile:

Yeah, =this.Cover isn’t a thing in core Obsidian — that’s why I thought you were using a plugin of some kind. Here’s the official help docs for reference: Index - Obsidian Help

1 Like

yes, you’re right, I installed dataview and for some strange reason I was thinking that =this.something was some core Obsidian feature and not a dataview feature…sorry and thanks again for patience and support!

We all get confused sometimes. :slightly_smiling_face:

1 Like

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