twill icon indicating copy to clipboard operation
twill copied to clipboard

Add options to blocks

Open joyceverheije opened this issue 2 years ago • 4 comments

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.

joyceverheije avatar Jun 08 '22 21:06 joyceverheije

That's a great idea, I will check this for Twill 3.x

haringsrob avatar Jun 10 '22 06:06 haringsrob

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.

alitak avatar Aug 10 '22 07:08 alitak

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

Screenshot 2023-02-13 at 12 20 39 PM Screenshot 2023-02-13 at 12 23 10 PM

devimako avatar Feb 13 '23 09:02 devimako

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,

haringsrob avatar Feb 13 '23 09:02 haringsrob