Skip to the content
Documentation

ContentView: old version (page id 6292140)

No ratings yet

Skip to end of metadata Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

ViewManager & ContentViewProvider

The role of the ViewManager is to select the right template for displaying a given content or location. It aggregates objects called content view providers which implement eZ\Publish\MVC\View\ContentViewProvider interface.

Each time a content is to be displayed through the Content\ViewController, the ViewManager iterates over the registered ContentViewProvider objects and calls either getViewForContent() or getViewForLocation() depending on the context.

Provided ContentViewProvider implementations

Name Usage
ConfiguredContentViewProvider Based on application configuration.
Formerly known as Template override system.
LegacyContentViewProvider Forwards view selection to the legacy kernel by running the old content/view module.
Pagelayout used is the one configured in exponential_legacy.view.default_layout.

Custom ContentViewProvider

When to develop a custom ContentViewProvider

  • You want a custom template selection based on a very specific state of your application
  • You depend on external resources for view selection
  • You want to override the default one (based on configuration) for some reason

ContentViewProvider objects need to be properly registered in the service container with the exponential.content_view_provider service tag.

Tag attribute name Usage
priority

An integer giving the priority to the ContentViewProvider in the ViewManager.

The priority range is from -255 to 255

Example

Custom ContentViewProvider

Parameters injection in content views

It is possible to dynamically inject variables in content view templates by listening to the exponential.pre_content_view event.

The event listener method receives an eZ\Publish\MVC\Event\PreContentViewEvent object

Example

Render embedded content objects

Rendering an embedded content from a Twig template is pretty straight forward:

Rendering from a location Id

ESI

Just as for regular Symfony controllers, you can take advantage of ESI and use different cache levels:

Using ESI

Asynchronous rendering

Symfony also supports asynchronous content rendering with the help of hinclude.js library.

Asynchronous rendering Icon hinclude.js needs to be properly included in your layout to work.

 

 

  • No labels

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.