# Image block preview

**URL:** <https://forum.getkirby.com/t/image-block-preview/27289>\
**Category:** Questions\
**Created:** [December 12, 2022, 7:22pm UTC](https://forum.getkirby.com/t/image-block-preview/27289 "2022-12-12T19:22:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 12, 2022, 7:22pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/1 "2022-12-12T19:22:16Z")

</div>

I want to change the block preview for image blocks.

I tried to use

> **[Blocks](https://getkirby.com/docs/reference/plugins/extensions/blocks)**

But I also saw here and there that it is not possible to overwrite the build in previews.

It looks like it is fixed here:

> <https://github.com/getkirby/kirby/issues/3776>
>
> \*\*Describe the bug\*\*  
> It's not possible to set the \`preview\` setting of defaul…t blocks to anything else but \`false\`. They are hardcoded to use their respective preview, so \`image\` for the image block or \`text\` for the text block.
> 
> \*\*To Reproduce\*\*  
> Steps to reproduce the behavior:
> 1. Create a custom block preview plugin or use https://github.com/jongacnik/kirby-fields-block
> 2. Set the \`preview\` of a default block to your custom preview or the \`fields\` preview:
> \`\`\`yml
> \# site/blueprints/blocks/image.yml
> 
> name: Image
> preview: fields
> fields:
> image:
> type: files
> multiple: false
> \`\`\`
> 3. The image block will still use the \`image\` preview
> 
> \*\*Expected behavior\*\*  
> The fields preview should be used.
> 
> \*\*Kirby Version\*\*  
> 3.5.7.1
> 
> \*\*Additional context\*\*  
> https://forum.getkirby.com/t/default-blocks-previews-hardcoded/23612

But when I copy the code from the first link, all plugins stop working.

What should I do to create a preview for the image block?

Thank you!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 12, 2022, 8:25pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/2 "2022-12-12T20:25:13Z")

</div>

What have you tried?

You need to create a plugin with an image preview.

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 8:28am UTC](https://forum.getkirby.com/t/image-block-preview/27289/3 "2022-12-13T08:28:20Z")

</div>

I followed this tutorial:

> **[Blocks](https://getkirby.com/docs/reference/plugins/extensions/blocks#full-block-plugins)**

But when I converted it to the Vue component, all plugins stopped working, or at least the previews from custom block plugins.  
So it is possible to overwrite the default preview?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 13, 2022, 8:36am UTC](https://forum.getkirby.com/t/image-block-preview/27289/4 "2022-12-13T08:36:40Z")

</div>

> [@johannesverwoerd](#):
>
> So it is possible to overwrite the default preview?

Yes, that should actually work fine, can’t test now, though.

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 8:50am UTC](https://forum.getkirby.com/t/image-block-preview/27289/5 "2022-12-13T08:50:10Z")

</div>

Apart from that, the tutorial does not work like it should.  
Bellow my code. Maybe I do something wrong?

index.js

```auto
import Button from "./components/Buttonasa.vue";

panel.plugin("your-project/button-block", {
  blocks: {
    button: Button
  }
});

```

index.php:

```auto
<?php

Kirby::plugin('your-project/button-block', []);

```

components/button.Vue:

```auto
<template>
  <input
    type="text"
    :placeholder="placeholder"
    :value="content.text"
    @input="update({ text: $event.target.value })"
  />
</template>

<script>
export default {
  computed: {
    placeholder() {
      return "Button text …";
    }
  }
};
</script>

<style>
.k-block-type-button input {
    border: 2px solid #000;
    border-radius: 3rem;
    padding: .25rem .75rem;
    cursor: pointer;
    font: inherit;
    text-align: center;
}
.k-block-type-button input:focus {
    outline: 0;
    border-color: var(--color-focus);
}
</style>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 13, 2022, 9:13am UTC](https://forum.getkirby.com/t/image-block-preview/27289/6 "2022-12-13T09:13:58Z")

</div>

Your file seems to be called button.Vue but you import `Buttonasa.vue`? Just a typo?

kirbyup should complain…

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 10:28am UTC](https://forum.getkirby.com/t/image-block-preview/27289/7 "2022-12-13T10:28:14Z")

</div>

That was just to temporarly disconnect the vue file. When I repair the path the issue remains the same: No other plugins seem to work. Also the preview of the button block does not seem to be effected.

Other then that this is just an issue I bumped in too, while working towards a custom preview of the image block. When I get the button preview to work, I might be able to figure out the image preview too. Thanks!

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 10:31am UTC](https://forum.getkirby.com/t/image-block-preview/27289/8 "2022-12-13T10:31:16Z")

</div>

The folder is called ‘site/plugins/button’.

The yaml does not mention a preview:

```auto
name: Button
icon: bolt
fields:
  location:
    label: field.blocks.image.location
    type: radio
    columns: 3
    default: "kirby"
    options:
      kirby: Kirby
      web: Web
      javascript: Javascript

```

I don’t think it matters but for the sake of completeness…

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [December 13, 2022, 10:39am UTC](https://forum.getkirby.com/t/image-block-preview/27289/9 "2022-12-13T10:39:56Z")

</div>

You need to assign the preview name in the yaml file.

And you also need to register your block blueprint in the index.php file.

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 11:25am UTC](https://forum.getkirby.com/t/image-block-preview/27289/10 "2022-12-13T11:25:24Z")

</div>

What would be the name, in the case of the above?  
And how do I register the block blueprint?

It is a bit strange that the tutorial is not leading towards a functional plugin right? or am I missing a step? Is there a page where I can learn more about the plugins, so I get a better understanding? I feel like I am asking stupid questions…

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [December 13, 2022, 11:49am UTC](https://forum.getkirby.com/t/image-block-preview/27289/11 "2022-12-13T11:49:35Z")

</div>

> **[Blocks](https://getkirby.com/docs/reference/plugins/extensions/blocks#full-block-plugins__adding-a-default-blueprint-and-snippet)**

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 1:08pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/12 "2022-12-13T13:08:31Z")

</div>

In the plugin I just want to change the preview of the block.  
The yml and php file are good as they are.  
Still in the dark here ☹

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 13, 2022, 1:12pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/13 "2022-12-13T13:12:54Z")

</div>

Please post the code you are using for the image block preview, so I can test it later.

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 7:07pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/14 "2022-12-13T19:07:49Z")

</div>

Thanks all!

Bellow the code:

image blueprint:

```auto
name: field.blocks.image.name
icon: image
preview: image
fields: etc…

```

site/plugins/jv-image-block/

index.php:

```auto
<?php

Kirby::plugin('jv/image-block', []);

```

index.js:

```auto
import Image from "./components/Image.vue";

panel.plugin("jv/image-block", {
  blocks: {
    image: image
  }
});

```

components/Image.vue

```auto
<template>
	<k-block-figure
		:caption="content.caption"
		:caption-marks="captionMarks"
		:empty-text="$t('field.blocks.image.placeholder') + ' …'"
		:is-empty="!src"
		empty-icon="image"
		@open="open"
		@update="update"
	>
		<template v-if="src">
			<k-aspect-ratio v-if="ratio" :ratio="ratio" :cover="crop">
				<img :alt="content.alt" :src="src" />
			</k-aspect-ratio>
			<img
				v-else
				:alt="content.alt"
				:src="src"
				class="k-block-type-image-auto"
			/>
		</template>
	</k-block-figure>
</template>

<script>
/**
 * @displayName BlockTypeImage
 * @internal
 */
export default {
	computed: {
		captionMarks() {
			return this.field("caption", { marks: true }).marks;
		},
		crop() {
			return this.content.crop || false;
		},
		src() {
			if (this.content.location === "web") {
				return this.content.src;
			}
			if (this.content.location === "parent") {
				return this.content.imageparent[0].url;
			}
			if (this.content.location === "all") {
				return this.content.imageall[0].url;
			}
			if (this.content.location === "site") {
				return this.content.imagesite[0].url;
			}
			if (this.content.image[0]?.url) {
				return this.content.image[0].url;
			}
			return false;
		},
		ratio() {
			return this.content.ratio || false;
		}
	}
};
</script>
<style>
.k-block-type-image .k-block-figure-container {
	display: block;
	text-align: center;
	line-height: 0;
}
.k-block-type-image-auto {
	max-width: 100%;
	max-height: 30rem;
}
</style>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 13, 2022, 7:10pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/15 "2022-12-13T19:10:56Z")

</div>

> [@johannesverwoerd](#):
>
> index.js:

Where is your index.js located?

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 7:11pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/16 "2022-12-13T19:11:20Z")

</div>

The plugin seems to have no other effect then to cancel the functionality of the other plugins.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 7:12pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/17 "2022-12-13T19:12:03Z")

</div>

site/plugins/jv-image-block/index.js  
site/plugins/jv-image-block/index.php  
site/plugins/jv-image-block/components/Image.vue

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 13, 2022, 7:14pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/18 "2022-12-13T19:14:21Z")

</div>

> [@johannesverwoerd](#):
>
> site/plugins/jv-image-block/index.js

But that doesn’t make sense. Since you are using a single file component, you need a package.json and the kirbyup bundler to create the final index.js next to the index.php.

Check out this recipe for an example: [Creating a custom block type from scratch | Kirby CMS](https://getkirby.com/docs/cookbook/panel/custom-block-type)

It seems though that we have an error in the docs linked above, because the example doesn’t mention this.

See also: [To bundle or not to bundle: differences of creating plugins with or without a build process | Kirby CMS](https://getkirby.com/docs/cookbook/panel/to-bundle-or-not-to-bundle)

---

<div class="post-metadata">

**Author:** ![johannesverwoerd](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johannesverwoerd](https://forum.getkirby.com/u/johannesverwoerd)\
**Post date:** [December 13, 2022, 7:31pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/19 "2022-12-13T19:31:35Z")

</div>

![Schermafbeelding 2022-12-13 om 20.30.32](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/9/94a641abc9f777534a4e42fafe35107d0c2a28ec.png)

The other plugin work again now, but the image preview still seems to have no effect.  
I added some text to see if it is used. But I don’t see the span ☹

```auto
<template>
<span>test</span>
	<k-block-figure
		:caption="content.caption"
		:caption-marks="captionMarks"
		:empty-text="$t('field.blocks.image.placeholder') + ' …'"
		:is-empty="!src"
		empty-icon="image"
		@open="open"
		@update="update"
	>
		<template v-if="src">
			<k-aspect-ratio v-if="ratio" :ratio="ratio" :cover="crop">
				<img :alt="content.alt" :src="src" />
			</k-aspect-ratio>
			<img
				v-else
				:alt="content.alt"
				:src="src"
				class="k-block-type-image-auto"
			/>
		</template>
	</k-block-figure>
</template>

<script>
/**
 * @displayName BlockTypeImage
 * @internal
 */
export default {
	computed: {
		captionMarks() {
			return this.field("caption", { marks: true }).marks;
		},
		crop() {
			return this.content.crop || false;
		},
		src() {
			if (this.content.location === "web") {
				return this.content.src;
			}
			if (this.content.location === "parent") {
				return this.content.imageparent[0].url;
			}
			if (this.content.location === "all") {
				return this.content.imageall[0].url;
			}
			if (this.content.location === "site") {
				return this.content.imagesite[0].url;
			}
			if (this.content.image[0]?.url) {
				return this.content.image[0].url;
			}
			return false;
		},
		ratio() {
			return this.content.ratio || false;
		}
	}
};
</script>
<style>
.k-block-type-image .k-block-figure-container {
	display: block;
	text-align: center;
	line-height: 0;
}
.k-block-type-image-auto {
	max-width: 100%;
	max-height: 30rem;
}
</style>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 13, 2022, 7:37pm UTC](https://forum.getkirby.com/t/image-block-preview/27289/20 "2022-12-13T19:37:16Z")

</div>

> [@johannesverwoerd](#):
>
> ```auto
> blocks: {
> image: image
> }
> 
> ```

Here’s a typo, the value should be uppercase since your are importing as Image, so

```auto
    image: Image

```

[Next page](https://forum.getkirby.com/t/image-block-preview/27289.md?page=2)
