Important

You are browsing the documentation for version 4.2 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.

Content Providers

OroPlatform is a hybrid application that supports JS navigation, but it still renders a lot on server side. Usually when a user changes the current page, the application reloads only the content part, so there are parts that not required to be rendered on sever side for each request. To allow a developer to include partial content in the hash navigation response, content providers were introduced.

Content Provider Implementation

To implement a content provider, you need to implement Oro\Bundle\UIBundle\ContentProvider\ContentProviderInterface and register your class as a service with tag oro_ui.content_provider. The alias attribute of this tag is required and it is used to specify a unique name of the content provider.

Note

If you want a content provider to be available on a storefront, tag it with oro_frontend.content_provider.

Optional Providers

By default, all content providers are enabled but if content generated by your provider is optional, you can pass the enabled: false attribute to the tag of provider’s service definition. After that, the content will not be added to response, but optional providers can be enabled if you pass their names through request parameter _enableContentProviders.

Twig

When a page is loaded for the first time, its content is mostly rendered by twig. To get content from the content providers from the twig template, use the oro_get_content Twig function.

Example:

Getting an array of all flash messages:

{% set contentProviderContent = oro_get_content(null, ['flashMessages'])|first %}

The first argument of this Twig function is an array contains an additional content. If there is no additional content, this argument can be null or empty array. The second argument of this Twig function is an array containing the names of context elements to be returned. If this argument is null or an empty array, all context elements will be returned.