Content Element
Creating a new content element
To add a custom content element, you’ll:
Define a Form Type
(Optional) Register the Form Type
Implement a Renderer
Register the Renderer
Create a Twig Template
Form Type
Create a new form type under src/Form/Type/ContentElements
location. Define your fields and remember to define public const TYPE
with a unique name.
For example, you can create a new form type called Text
:
(Optional) Register the Form Type
If your form type have constructor with some arguments, define constant parameter in config/parameters.yaml
or yours any other yaml
file:
If your form type doesn't have any constructor arguments, you can skip this step, because compiler pass will automatically define it for you.
If your form type have constructor with some arguments, you must define form type in service container under config/services.yml
with correct tags:
If your form type doesn't have any constructor arguments, you can skip this step, because compiler pass will automatically register it for you.
Implement a renderer
Create a new renderer class under src/Renderer/ContentElement
location. Extend Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement
class.
For example, you can create a new renderer called TextContentElementRenderer
:
Register a renderer
Register your renderer with tag in service container under config/services.yml
:
Define form_type only if your form type doesn't have constructor with additional arguments.
Create a Twig Template
Finally, create a new template under templates/bundles/SyliusCmsPlugin/Shop/ContentElement
location.
For example, you can create a new template called _text.html.twig
:
Last updated
Was this helpful?