The configured ViewProvider allows you to configure template selection when using the ViewController, either directly from a URL or via a sub-request.

In eZ Publish 4.x, it was known as template override system by configuration (override.ini).
However this only reflects old overrides for node/view/*.tpl and content/view/*.tpl.

Principle

The configured ViewProvider takes its configuration from your siteaccess in the content_view section. This configuration is a hash built in the following way:

# app/config/ezplatform.yml
ezpublish:
    system:
        # Can be a valid siteaccess, siteaccess group or even "global"
        front_siteaccess:
            # Configuring the LocationViewProvider
            content_view:
                # The view type (full/line are standard, but you can use custom ones)
                full:
                    # A simple unique key for your matching ruleset
                    folderRuleset:
                        # The template identifier to load, following the Symfony bundle notation for templates
                        # See http://symfony.com/doc/current/book/controller.html#rendering-templates
                        template: eZDemoBundle:full:small_folder.html.twig
                        # Hash of matchers to use, with their corresponding values to match against
                        match:
                            # Key is the matcher "identifier" (class name or service identifier)
                            # Value will be passed to the matcher's setMatchingConfig() method.
                            Identifier\ContentType: [small_folder, folder]

Template matching will NOT work if your content contains a Field Type that is not supported by the repository. It can be the case when you are in the process of a migration from eZ Publish 4.x, where custom datatypes have been developed.
In this case the repository will throw an exception which is caught in the ViewController, causing a fallback to the legacy kernel.

The list of Field Types supported out of the box is available here.

You can define your template selection rules in a different configuration file. Read the cookbook recipe to learn more about it.

You can also use your own custom controller to render a content/location.

About location_view & content_view

Until eZ Publish Platform 5.4, the main view action was location_view. This is deprecated since eZ Platform 15.12 (1.0). Only content_view should be used to view content, with a location as an option.

Existing location_view rules will be, when possible, converted transparently to content_view, with a deprecation notice. However, it is not possible to do so when the rule uses a custom controller.
In any case, location_view rules should be converted to content_view ones, as location_view will be removed in the next kernel major version.

Matchers

To be able to select the right templates against conditions, the view provider uses matcher objects, all implementing eZ\Publish\Core\MVC\Symfony\View\ContentViewProvider\Configured\Matcher interface.

Matcher identifier

The matcher identifier can comply to 3 different formats:

  1. Relative qualified class name (e.g. Identifier\ContentType). This is the most common case and used for native matchers. It will then be relative to eZ\Publish\Core\MVC\Symfony\View\ContentViewProvider\Configured\Matcher.
  2. Full qualified class name (e.g. \Foo\Bar\MyMatcher). This is a way to specify a custom matcher that doesn't need specific dependency injection. Please note that it must start with a \.
  3. Service identifier, as defined in Symfony service container. This is the way to specify a more complex custom matcher that has dependencies.

If your matcher needs the repository, simply make it implement eZ\Publish\Core\MVC\RepositoryAwareInterface or extend the eZ\Publish\Core\MVC\RepositoryAware abstract class. The repository will then be correctly injected before matching.

Matcher value

The value associated to the matcher is being passed to its setMatchingConfig() method and can be anything supported by the matcher.

In the case of native matchers, they support both scalar values or arrays of scalar values.
Passing an array amounts to applying a logical OR.

Combining matchers

It is possible to combine matchers to add additional constraints for matching a template:

# ...
match:
    Identifier\ContentType: [small_folder, folder]
    Identifier\ParentContentType: frontpage

The example above can be translated as "Match any content which ContentType identifier is small_folder OR folder, AND having frontpage as ParentContentType identifier".

Available matchers

The following table presents all native matchers.

IdentifierDescription
Id\ContentMatches the ID number of the Content item
Id\ContentTypeMatches the ID number of the Content Type that the Content item is an instance of
Id\ContentTypeGroupMatches the ID number of the group containing the Content Type that the Content item is an instance of
Id\LocationMatches the ID number of a Location.
In the case of a Content item, matched against the main location.
Id\ParentContentTypeMatches the ID number of the parent Content Type.
In the case of a Content item, matched against the main location.
Id\ParentLocation

Matches the ID number of the parent Location.
In the case of a Content item, matched against the main location.

Id\RemoteMatches the remoteId of either content or Location, depending on the object matched.
Id\SectionMatches the ID number of the Section that the Content item belongs to.
Id\StateNot supported yet.
Identifier\ContentTypeMatches the identifier of the Content Type that the Content item is an instance of.
Identifier\ParentContentType

Matches the identifier of the parent Content Type.
In the case of a Content item, matched against the main Location. 

Identifier\SectionMatches the identifier of the Section that the Content item belongs to.
Identifier\StateNot supported yet.
DepthMatches the depth of the Location. The depth of a top level Location is 1.
UrlAlias

Matches the virtual URL of the Location (i.e. /My/Content-Uri).

Important: Matches when the UrlAlias of the location starts with the value passed.
Not supported for Content (aka content_view). 

 

Related topics: