add doc for block builder vars
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
70875092f5
commit
c4ba316d7f
|
@ -99,6 +99,7 @@ class CustomBlock extends BuilderBlock
|
|||
->setIsContainer(false) // set `true` if the block can contain blocks
|
||||
->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
->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 }}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue