diff --git a/docs/utils/editors/builder.md b/docs/utils/editors/builder.md index 5e864e1..b699e4c 100644 --- a/docs/utils/editors/builder.md +++ b/docs/utils/editors/builder.md @@ -99,6 +99,7 @@ class CustomBlock extends BuilderBlock ->setIsContainer(false) // set `true` if the block can contain blocks ->setIcon('') ->setTemplate('builder_block/custom.html.twig') + ->setClass('col-md-12') ->addSetting(name: 'value', label: 'Value', type: 'textarea', attributes: [], default: 'Default value') ; } @@ -126,3 +127,28 @@ That's all folks! ## Rendering To render blocks, simply use `{{ value|block_to_html }}`. + +If you need to build variables depending of the content, you can override the method `buildVars`: + +```php-inline title="src/BuilderBlock/CustomBlock.php" +namespace App\BuilderBlock; + +use App\Core\BuilderBlock\BuilderBlock; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; + +#[AutoconfigureTag('builder_block.widget')] +class CustomBlock extends BuilderBlock +{ + public function buildVars(array $data) + { + $this->vars['bar'] = 'bar'; + } +} +``` + +And you can access variables in the template: + +```twig-inline title="templates/builder_block/custom.html.twig" +{{ vars.bar }} +``` +