Message-ID: <668904804.3326.1485852726334.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3325_25480514.1485852726334" ------=_Part_3325_25480514.1485852726334 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 you to configure tem= plate selection when using the ViewController, either directly= from 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 content_view section. This configuration is a hash built in the following way= :

=20
# 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 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

Tip

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

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

Ab= out location_view & content_view

Until eZ Publish Platform 5.4, the main view action was location_v= iew. This is deprecated since eZ Platform 15.12 (1.0). Only content_view should be used to view content, with a location as a= n 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 c= ontroller.
In any case, location_view rules should be conve= rted 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 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 extend the eZ\Pub= lish\Core\MVC\RepositoryAware abstract class. The repository will th= en 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 can be translated as "Match any content which = ContentType identifier is small_folder OR fol= der, AND having frontpage as ParentContentType identifier".

Available matchers

The following table presents all native matchers.

Identifier Description
Id\Content Matches the ID number of the Conte= nt item
Id\ContentType Matches the ID number of the Conte= nt Type that the Content item is an instance of
Id\ContentTypeGroup Matches the ID number of the= group containing the Content Type that the Content item is an instance of<= br>
Id\Location Matches the ID number of a Location.
In t= he case of a Content item, matched against the main location.
Id\ParentContentType<= /td> Matches the ID number of the paren= t Content Type.
In the case of a Content item, matched against the m= ain location.
Id\ParentLocation

Matches the ID number of the pa= rent Location.
In the case of a Content item, matched against the ma= in location.

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 that the Content item belongs to.
Id\State Not supported yet.
Identifier\ContentType Matches the identifier of th= e 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 aga= inst the main Location. 

Identifier\Section Matches the identifier of the Sect= ion that the Content item 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). 

 

Related topics:
------=_Part_3325_25480514.1485852726334--