nirsh
August 28, 2022, 9:49am
1
Hello everyone
I try to create a custom block, I call it “info-item”. I need to have a block that has 3 text fields in it.
Therfore I followed this tutorial .
the problem is: when I try to add this info-item block in the panel it doesn’t show the drawer, it just adds a new empty block line with no option to edit.
I suspect I’m doing something wrong in the index.php file of the plugin, it looks like this:
<?php
Kirby::plugin('TERK/infoitem-block', [
'blueprints' => [
'blocks/infoitem' => __DIR__ . '/blueprints/blocks/infoitem.yml',
],
'snippets' => [
'blocks/infoitem' => __DIR__ . '/snippets/blocks/infoitem.php',
],
]);
my plugin folder looks like this:
and my new block item yml looks like this:
name: infoitem
sections:
something:
type: fields
fields:
years:
type: text
name:
type: text
location:
type: text
What am I doing wrong?
Thank you!
You cannot use sections
in a block yaml.
nirsh
August 28, 2022, 10:25am
3
Wow thanks so much! it works perfectly :)))
nirsh
August 28, 2022, 12:37pm
4
Another small issue I’m having with custom blocks.
I try to customize it’s appearance in the panel so I use the index.js file like this:
panel.plugin("TERK/infoitem-block", {
blocks: {
infoitem: {
template: `
<div>
<div><p>yo yo yo</p></div>
</div>
`
}
}
});
But for some reason - nothing changes. it just show me the name of the block.
Any idea why?
Should work. Where did you put your index.js?
nirsh
August 28, 2022, 2:12pm
6
next to index.php
like this:
Hm, that’s weird. From what you copied here, the plugin name seems to be identical in index.php and index.js, but double check just in case.
Which Kirby version are you using?
nirsh
August 28, 2022, 2:32pm
8
the names are identical
by the way - I get these messages in the console:
maybe it can help?
(I added the hiii just to see if it even reads the file)
The "Plugin is replacing “k-block-type-markdown” is just a debugging message, probably comes from the markdown field plugin?
Again, which Kirby version are you using?
nirsh
August 28, 2022, 2:46pm
10
ah that’s right - I use this plugin too…
I think it’s 3.7.0.2
That’s what the composer.json in the kirby folder says
Try to set the preview in your block yaml (shouldn’t be necessary, but maybe it is in your older version)
name: infoitem
preview: infoitem
fields:
# rest of stuff
1 Like
nirsh
August 28, 2022, 2:54pm
12
Amazing! it works now!
Thank you so much!