Custom block not rendering ๐Ÿ˜…

Hello all! :relaxed:

I am in the process of creating my first custom plugin and have followed tutorials such as the one found at Creating a custom block type from scratch | Kirby CMS. I have set up all the necessary files and folders, and it is functioning properly in the panel and it results well in the page content txt.

However, when I want to render it in the front-end, the block doesnt appear.

<div class="block-type-mediaplayer"> 
/*snippet should be here*/

As you can see, its type is well render. I believe it cannot access its snippet (???). However I followed the guide and made my inded.php like this:

Kirby::plugin('website/mediaplayer-block', [
  'blueprints' => [
    'blocks/mediaplayer' => __DIR__ . '/blueprints/blocks/mediaplayer.yml',
  'snippets' => [
    'blocks/mediaplayer' => __DIR__ . '/snippets/blocks/mediaplayer.php',

and the snippet mediaplayer.php is obviously not empty haha.

Here is my file structure if needed:
Screenshot 2023-01-19 at 12.55.45

I certain I have missed something, but I am unable to identify the error even after reading the guide 3 times :sweat_smile:

Could you post the snippet, please?

Hey @texnixe,

My snipped is:

<article class="videoContainer">

<video class="videoContainer__video videoContainer__video--dimmed"  poster="<?php echo $block->cover()->toFile()->url(); ?>">
  <source src="<?php echo $block->file()->toFile()->url(); ?>" type="video/mp4">
  Your browser does not support the video tag.

<button class="videoContainer__play text--smallCaps"><span class="videoContainer__playIcon">โ–บ</span><?php echo $block->name()?></button>


But even with <p>xxxx</p> it doesnโ€™t find the snippetโ€ฆ

This code should never be used without a check if the file exist before calling url().

But if it doesnโ€™t work with all this code removed, then there seems to be another issue. Are you rendering the blocks normally with $page->blocksfieldname()->toBlocks()?

This is the section I am using:

				<?php foreach ($subpage->film()->toBlocks() as $block): ?>
					<div class="block block-type-<?= $block->type() ?>">
						<?php $block ?>
				<?php endforeach ?>

The โ€œtestโ€ p is visibleโ€ฆ

Oh godโ€ฆ I just realised I missed the โ€œechoโ€ it works now, so sorry haha. Devil is in the detailsโ€ฆโ€ฆ

Just on a side note: If I were you, Iโ€™d use either always the short echo tag <?= (preferable) or <?php echo but never mix both in your code. Consistent code styles are important for readability.

1 Like

Ok, noted! Thanks!