question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for images in fields

See original GitHub issue

I am not sure if this is possible, but maybe it can be done. I would like to be able to link to a remote or local image in a yaml field, and have dataview render that image in preview mode.

So something like:

---
image: ![](URLtoimage.com/image.jpg)
# OR
image: [](URLtoimage.com/image.jpg)
# OR
image: URLtoimage.com/image.jpg
---

Where you could then have a table calling for the image field

table image from ""

I know yaml won’t render the image in preview mode, but perhaps dataview could have an image type which passes the image path to <img src="{{path}}"> or something.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:13
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
nkodercommented, Sep 9, 2021

Interesting! It might make my custom JS code obsolete.

Below I share my handmade image-from-frontmatter rendering approach for some “how do they overcome of such feature” context 😄


Currently, in YAML front matter I have e.g.:

thumbnail: "084 Interstellar Backdoor (x1).png"

then in dataviewjs I have:

const {DataviewHelpers} = customJS;

dv.table(
	[
		"thumbnail",
		"something else",
	],
	dv.pages(`"${dv.current().file.folder}"`)
		.filter(page => page.file.name !== dv.current().file.name)
		.map(page => [
			renderThumbnailOf(page),
			"other value",
		])
);

function renderThumbnailOf(page) {
	const path = `${page.file.folder}/${page.thumbnail}`;
	const containerStyle = `
		height: 100px;
		width: 100px;
	`;
	return `
		<div style="${containerStyle}">
			${DataviewHelpers.renderThumbnail({
				thumbnailPath: path,
				type: "bg",
			})}
		</div>
	`.trim();
}

and then, last but not least, shared helper function:

class DataviewHelpers {
    renderThumbnail({thumbnailPath, type}) {
        const abstractFile = app.vault.getAbstractFileByPath(thumbnailPath);
        const resourcePath = abstractFile
            ? app.vault.getResourcePath(abstractFile)
            : null;

        if (!resourcePath) return null;

        if (type === "bg") {
            const style = `
                width: 100%;
                height: 100%;
                background-image: url('${resourcePath}');
                background-repeat: no-repeat;
                background-position-x: center;
                background-position-y: center;
                background-size: contain;
            `;
            return `<div style="${style}"></div>`;
        }

        if (type === "img") {
            const style = `
                width: 100%;
                object-fit: contain;
            `;
            return `<img style="${style}" src="${resourcePath}">` ;
        }

        throw Error(`Thumbnail type "${type}" is not supported.`)
    }
}

Another use case I have is with multiple thumbnails (I render them all inside a single table cell), like:

thumbnails:
  - "066 Grumman F-11 Tiger - F11 Keycap (social media).png"
  - "067 Kung Fury Time Travel - Enter and Backslash Pipe Keycaps (social media).png"
2reactions
CreepyBasticommented, Nov 2, 2022

My goal was to have a book library with LOCAL Cover images using YAML and DataView.

Just put your normal png link in to YAML and put " on each side.

---
Cover: "![[YourImageName.png]]"
---

Then simply table for Cover like with any other text.

```dataview
TABLE
Cover
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom fields support for file and image fields - ProcessWire
Custom fields support for file and image fields: misinformation?
Read more >
Support for Image and Date fields in Acroforms - Adobe Support
buttonImportIcon() now supports Image file types – jpg, png, gif, and tiff – in Reader. You can import these image files in Reader...
Read more >
Use Images in 'Formula' Fields - Salesforce Help
Use Images in 'Formula' Fields ; Create a public folder to hold your image files. · Click Create New Folder. Enter the folder...
Read more >
“Pick image from: custom field” – how does this work?
Support » Plugin: WordPress Popular Posts » “Pick image from: custom field” – how does this work? “Pick image from: custom field” – ......
Read more >
How to Add Image Choices to WPForms
In addition to any other customization options available for the field you're using, two options are added when the Use image choices option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found