I want to display in a dataview table all the files that have the tag #software and in case the note has an image in the img property, display the image.
This is the code I use:
TABLE embed(link(meta(img).path,"50")) as "img"
FROM #software
Unfortunately, using this code, the dataview table displays only notes that have BOTH #software tag and an image in the img property.
Instead, I would like to display also files that have #software tag but don’t have an image in the img property.
TABLE embed(link(meta(img).path,"50")) as "img",rating,os,description
FROM #software
WHERE !contains(lower(file.folder), "template")
SORT file.ctime DESC
If I remove embed(link(meta(img).path,"50")) as "img" even the notes without images are displayed correctly.
I think that, to make it work, I have to add some code that if there isn’t an image in “img”, then ignore embed(link(meta(img).path,"50")) as "img". But I don’t know how to achieve it.
Thank you, I tried using choice but the results with no image still don’t appear. This is the code I tried:
TABLE choice(img, embed(link(meta(img).path,"50")), "") as "img",rating,os,description
FROM #software
WHERE !contains(lower(file.folder), "template")
SORT file.ctime DESC
Your issue most likely arises from the fact that you’re trying to do meta(img).path when img is empty, which trigger an exception causing those rows to be removed.
Try replacing it with something like: meta( default(img, "...dummyImg...")).path where the dummy img is some valid link to an image in your vault to be used as a placeholder image.
TABLE embed(link(meta( default(img, [[NoImageAvailable.png]])).path,"50")) as "img",rating,os,description
FROM #software
WHERE !contains(lower(file.folder), "template")
SORT file.ctime DESC
When you’re in dataviewjs you’ll need to use the javascript variants of functions:
You can to some extent use the dv.func.XXX to access the DQL variant of a function, but there might be some variations in how to work with a given function. DQL is a different beast when compared to dataviewjs.