Conditionally hide individual Builder blocks from the "Add items" list

Hi all. Does anyone know of a way to conditionally hide individual blocks from the "add content" list of the Builder field? I've got a situation where users should only be able to add 1 of each block type. cheers
2 Replies
RustyTrombone
RustyTrombone10mo ago
Digging up an old question, but did you ever figure this out? I'm creating a page builder that has multiple pages, but each page has different Blocks - some blocks cannot be used on some pages. For anyone else looking, I did something like this in my resource:
$availableBlocks = self::getAvailableBlocks($form->getRecord()->template);
$availableBlocks = self::getAvailableBlocks($form->getRecord()->template);
protected static function getAvailableBlocks(string $template)
{
$blocks = [
'index' => [
// Builder blocks for my index template
],
'about' => [
// Builder blocks for my about template
],
];

return $blocks[$template] ?? [];
}
protected static function getAvailableBlocks(string $template)
{
$blocks = [
'index' => [
// Builder blocks for my index template
],
'about' => [
// Builder blocks for my about template
],
];

return $blocks[$template] ?? [];
}
Then just give that to the Builder
->blocks($availableBlocks)
->blocks($availableBlocks)
binaryfire
binaryfireOP10mo ago
Yeah I submitted a PR for this: https://github.com/filamentphp/filament/pull/9931. The info is in the docs.
Want results from more Discord servers?
Add your server