From c4ba316d7f2c239ee0fd24e9162cd2754d3af33f Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 13 May 2024 11:20:28 +0200 Subject: [PATCH] add doc for block builder vars --- docs/utils/editors/builder.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 }} +``` +