Custom components¶
The back office has designated places where you can use your own components.
Components enable you to inject widgets (for example, My dashboard blocks) and HTML code (for example, 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 is displayed. The available groups are:
stylesheet-headscript-headstylesheet-bodyscript-bodycontent-edit-form-beforecontent-edit-form-aftercontent-create-form-beforecontent-create-form-afterdashboard-blocksdashboard-all-tab-groupsdashboard-my-tab-groupscontent-type-tab-groupscalendar-widget-beforelogin-form-beforelogin-form-afterglobal-search
Base component classes¶
If you only need to inject a short element (for example, a Twig template or a CSS link) without writing a class, you can make use of the following base classes:
TwigComponentrenders a Twig template.LinkComponentrenders the HTML<link>tag.ScriptComponentrenders 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:
1 2 3 4 5 6 7 8 | |
1 2 3 4 5 6 7 8 | |