twill
twill copied to clipboard
Add options to blocks
I would like to be able to pass some options through the blocks to avoid creating a new block for each variation I need.
For example, we create a lot of lite version of blocks with less fields, for different templates. Which means creating a new one and extracting or duplicating the initial form, to enrich it or simplify it.
Example block form:
@formField('medias', [
'name' => 'image',
'label' => 'Image',
])
@formField('radios', [
'name' => 'ratio',
'label' => "Ratio",
'options' => collect(['Full' => 'Full', 'Half' => 'Half']),
'default' => 'Full',
'inline' => true
])
@formField('checkbox', [
'name' => 'border',
'label' => 'Show border'
])
@formField('checkbox', [
'name' => 'background_color',
'label' => 'Show background color'
])
Example block lite form:
@formField('medias', [
'name' => 'image',
'label' => 'Image',
])
@formField('radios', [
'name' => 'ratio',
'label' => "Ratio",
'options' => collect(['Full' => 'Full', 'Half' => 'Half']),
'default' => 'Full',
'inline' => true
])
@formField('checkbox', [
'name' => 'border',
'label' => 'Show border'
])
Solution:
@formField('medias', [
'name' => 'image',
'label' => 'Image',
])
@formField('radios', [
'name' => 'ratio',
'label' => "Ratio",
'options' => collect(['Full' => 'Full', 'Half' => 'Half']),
'default' => 'Full',
'inline' => true
])
@formField('checkbox', [
'name' => 'border',
'label' => 'Show border'
])
@if($withBackgroundColor)
@formField('checkbox', [
'name' => 'background_color',
'label' => 'Show background color'
])
@endif
Module form:
@formField('block_editor', [
'blocks' => [
'text',
'image' => [
'withBackgroundColor' => true,
],
]
])
With the multiple block editor feature, I assume a use case would be to pass the same block with different options to different block editors within the same form, but I know this will be more complex to support because of the block templates inlined in the html once per block type.
That's a great idea, I will check this for Twill 3.x
Hello,
I would to add some other feature request for this idea.
It would be nice if I could pass some formField attributes to the block editor, like this:
@formField('block_editor', [
'blocks' => [
'quote' => [
'quote' => ['translated' => true],
],
'text',
'image',
],
])
As a result of this the inputField named quote in the block editor quote would be translatable and we should not create a custom block editor only because of some custom attributes.
how to separate the two blocks in the same module because i am getting all the block if i use in the same module
i need to use this blocks as separate for each section in page


Hey @devimako please use discussions or our discord for asking questions. Do not use unrelated issues, it will not get you the help you need faster.
Kind regards,