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.
/*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:
'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:
I certain I have missed something, but I am unable to identify the error even after reading the guide 3 times
Could you post the snippet, please?
My snipped is:
<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
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
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.