Message-ID: <1907917985.3048.1485851768200.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3047_318659937.1485851768200" ------=_Part_3047_318659937.1485851768200 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html View provider configuration

View provider configuration

=20 =20

The configured ViewProvider allows to configure templat= e selection when using the ViewController, either directly fro= m a URL or via a sub-request.

eZ Publish 4.x terminology

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 con= tent/view/*.tpl.

Principle

The configured ViewProvider takes its configuration fro= m your siteaccess in the location_view/content_view section (most of the time y= ou want to match a location, so we'll focus on location_view c= onfiguration). This configuration is a hash built in the following w= ay:

=20
# ezpublish/config/ezpublish.yml
ezpublish:
    system:
        # Can be a valid siteaccess, siteaccess group or even "global"
        front_siteaccess:
            # Configuring the LocationViewProvider
            location_view:
                # The view type (full/line are standard, but you can use cu=
stom ones)
                full:
                    # A simple unique key for your matching ruleset
                    folderRuleset:
                        # The template identifier to load, following the Sy=
mfony bundle notation for templates
                        # See http://symfony.com/doc/current/book/controlle=
r.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 o=
r service identifier)
                            # Value will be passed to the matcher's setMatc=
hingConfig() method.
                            Identifier\ContentType: [small_folder, folder]<=
/pre>=20

Important note about template matching

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 custo= m datatypes have been developed.
In this case the repository will throw= an exception which is caught in the ViewController, c= ausing the fallback to th= e legacy kernel.

The list of field types supported out of the box is available here.

Tip

You can define your template selection rules in a different configuratio= n file. Read the coo= kbook recipe to learn more about it.

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

 

Matchers

To be able to select the right templates against conditions, the view pr= ovider uses matcher objects, all implementing eZ\Publish\Core\MV= C\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\C= ontentType). This is the most common case and used for native matche= rs. It will then be relative to eZ\Publish\Core\MVC\Symfony\View= \ContentViewProvider\Configured\Matcher.
  2. Full qualified class name (e.g. \Foo\Bar\MyMatch= er). This is a way to specify a custom matcher that= doesn't need specific dependency injection. Please note that it mu= st start with a \.
  3. Service identifier, as defined in Symfony service cont= ainer. This is the way to specify a more complex custom matcher that has dependencies.

Injecting the Repository

If your matcher needs the repository, simply make it implement eZ\= Publish\Core\MVC\RepositoryAwareInterface or simply extend 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 se= tMatchingConfig() method and can be anything supported by the m= atcher.

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

Combining matchers

It is possible to combine matchers to add additional constraints for mat= ching a template:

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

The example above results to say "Match any content which Conten= tType identifier is small_folder OR folder, AND having frontpage as Pare= ntContentType identifier".

Available matchers

The following table presents all native matchers.

Identifier Description
Id\Content Matches the ID number of the conte= nt
Id\ContentType Matches the ID number of the conte= nt type whose content is an instance of
Id\ContentTypeGroup Matches the ID number of the= group of the content type whose content is an instance of belongs to
Id\Location Matches the ID number of a location.
In t= he case of a Content, matched against the main location.
Id\ParentContentType<= /td> Matches the ID number of the paren= t content type.
In the case of a Content, matched against the main l= ocation.
Id\ParentLocation

Matches the ID number of the pa= rent location.
In the case of a Content, matched against the main lo= cation.

Id\Remote Matches the remoteId of either content or locati= on, depending on the object matched.
Id\Section Matches the ID number of the secti= on whose content belongs to
Id\State Not supported yet.
Identifier\ContentType Matches the identifier of th= e content type whose content is an instance of
Identifier\ParentContentType=

Matches the identifier of= the parent content type.
In the case of a Content, matched against = the main location. 

Identifier\Section Matches the identifier of the sect= ion whose content belongs to
Identifier\State Not supported yet.
Depth Matches the depth of the loc= ation. The depth of a top level location is 1.
UrlAlias

Matches the virtual URL o= f 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 cont= ent_view). 

 

 

------=_Part_3047_318659937.1485851768200--