Closed assertchris closed 8 months ago
Hey, @assertchris! Can you tell me what you are experiencing or try to achieve? Why do you need the JS code in the template? I thought it had to do with having a block without any really useful form fields.
So I quickly tried to implement a separator block:
<?php
namespace App\Filament\Blocks;
use Closure;
use Statikbe\FilamentFlexibleContentBlocks\ContentBlocks\AbstractContentBlock;
class SeparatorBlock extends AbstractContentBlock
{
public static function getName(): string
{
return 'pubmus.separator';
}
public static function getIcon(): string
{
return 'heroicon-o-building-library';
}
public static function getLabel(): string
{
return 'Separator';
}
public static function getFieldLabel(string $field): string
{
return 'Separator';
}
protected static function makeFilamentSchema(): array|Closure
{
return [];
}
public function render()
{
return view('filament.blocks.separator');
}
public function getSearchableContent(): array
{
return [];
}
}
and the blade component:
<div>
<hr/>
</div>
For me it works.
Sorry for not giving more context for this. The issue I was having (and why I added the JS) was: even when providing an empty form schema array, the container is still added and visible:
The JS removes the empty container element. I am considering adding additional JS to remove the collapse/expand arrow if it's present.
The blade code wasn't for the frontend, it was for the filament UI.
@assertchris That's related to the way the UI of the block works of the Filament Builder. Maybe you can post this as a filament issue.
I will close this, since it is not related to the functionality of this package. Sorry!
Ok, cool. Thanks for the quick turn-around.
Forgive the template I've used, selecting anything other than "report a bug" leads to a 404 on GitHub. 🤷♂️
I find myself needing to make blocks that are placeholders with special meaning. For example, a client has requested I create a "separator" block that has no "content" but is just a placeholder so that the API can tell their app team to insert an app-specific separation between content.
The field looks like this:
The way I have achieved this is as follows:
...And, in the view:
I'm not a fan of this kind of JS approach but I can't think of any other way to "collapse" (without allowing expansion) of a custom block. I can imagine a
public static function hasNoFields(): bool
that the custom block could implement, which the renderer could use to omit thex-show=!isCollapsed
div.