Important
You are browsing documentation for version 6.0 of OroCommerce, supported until 2028. Read the documentation for the latest LTS version 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 JavaScript navigation, but much of the content is still rendered server-side. When a user changes the current page, the application typically reloads only the content portion. To avoid rendering unnecessary parts on the server for each request, content providers were introduced. They allow developers to include partial content in the hash navigation response.
Content Provider Implementation
To implement a content provider:
Implement the interface
Oro\Bundle\UIBundle\ContentProvider\ContentProviderInterfaceRegister your class as a service with the tag
oro_ui.content_provider
The alias attribute of this tag is required and specifies a unique name for the content provider.
Note
To make a content provider available in the storefront, use the tag oro_frontend.content_provider.
Optional Providers
By default, all content providers are enabled.
If the content generated by your provider is optional, set enabled: false in the service definition.
Optional providers will not be included in the response unless their names are passed through the request parameter _enableContentProviders.
Twig
When a page is loaded for the first time, most content is rendered by Twig.
To retrieve content from content providers in a Twig template, use the oro_get_content function.
Example: Getting an array of all flash messages:
{% set contentProviderContent = oro_get_content(null, ['flashMessages'])|first %}
Arguments of oro_get_content:
First argument – an array of additional content. If none, this can be null or an empty array.
Second argument – an array of context element names to return. If null or empty, all context elements will be returned.