Important
You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Widgets on a CMS Content Page¶
Widgets are only supported by a CMS content page, but you can also add support to any text variables.
Widgets enable you to render any html text generated by your custom PHP code, such as a marketing banner or a contact form.
To register a new widget, you should add a class that extends Oro\Bundle\CMSBundle\Widget\WidgetInterface
and implements the render method that applies argument widget options and returns the generated html text as a string.
Simple scalar values should be used as widget options which can be added by an administrator.
You should register every widget in the service container with the oro_cms.widget tag. Each tag should have a user-friendly alias which is used by an administrator to refer to a certain widget when managing the content that supports widgets.
1 # AppBundle/Resources/config/services.yml
2
3 acme_demo.contact_us_form:
4 class: 'AppBundle\Widget\ContactFormWidget'
5 lazy: true
6 tags:
7 - {name: oro_cms.widget, alias: contact_form}
Then an administrator can use the widget mentioned above in supported blocks with the {{ widget(‘contact_form’, {foo: ‘bar’}) }} placeholder where foo: bar is an option with the value available in the WidgetInterface::render() method.
Note
Mark the widgets as lazy: true to enable their loading only on the pages where they are used.
To support widgets in any text, you should apply the render_content filter in a twig template.
1 {{ entity.content | render_content }}