Injecting custom components¶
The Back Office has designated places where you can use your own components.
Components enable you to inject widgets (e.g. My dashboard blocks) and HTML code (e.g. a tag for loading JS or CSS files).
A component is any class that implements the Renderable
interface.
It must be tagged as a service in config/services.yaml
:
1 2 3 |
|
group
indicates where the widget will be displayed. The available groups are:
stylesheet-head
script-head
stylesheet-body
script-body
content-edit-form-before
content-edit-form-after
content-create-form-before
content-create-form-after
dashboard-blocks
dashboard-all-tab-groups
dashboard-my-tab-groups
content-type-tab-groups
calendar-widget-before
login-form-before
login-form-after
Base component classes¶
If you only need to inject a short element (e.g. a Twig template or a CSS link) without writing a class, you can make use of the following base classes:
TwigComponent
renders a Twig template.LinkComponent
renders the HTML<link>
tag.ScriptComponent
renders the HTML<script>
tag.
In this case, all you have to do is add a service definition (with proper parameters), for example:
1 2 3 4 5 6 7 8 9 10 11 |
|
This renders the path/to/file.html.twig
template with first_param
and second_param
as parameters.
With LinkComponent
and ScriptComponent
you provide $href
and $src
as arguments, respectively:
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 8 |
|