Message-ID: <1363444277.4026.1485856404658.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4025_95895776.1485856404658" ------=_Part_4025_95895776.1485856404658 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Content and Location view providers

Content and Location view providers

=20 =20

V= iew\Manager & View\Provider

The role of the (eZ\Publish\Core\MVC\Symfony\)View\Manager is to select the right template for displaying a given co= ntent item or location. It aggregates objects called content and locati= on view providers which respectively implement eZ\Publ= ish\Core\MVC\Symfony\View\Provider\Content and eZ\Pu= blish\Core\MVC\Symfony\View\Provider\Location interfaces.

Each time a content item is to be displayed through the Content\Vi= ewController, the View\Manager iterates over the regist= ered content or location View\Provider objects and calls&= nbsp;getView().

Provided View\Provider implementations

Name Usage
View provider configuration

Based on application configuration.
Former= ly known as Template override system.

eZ\Publish\Core\MVC\Legacy\View\Provide= r\Content

eZ\Publish\Core\MVC\Legacy\View\Provider\Locat= ion

Forwards view selection to the legacy kernel = by running the old content/view module.
Pagelayout used is the one confi= gured in ezpublish_legacy.<scope>.view_default_layout.For more details about the <scope> please refer to the= scope configuration d= ocumentation.

Custom View\= Provider

Difference between View\Provider= \Location and View\Provider\Content

When to develop a custom View\Provider\(Location= |Content)

View\Provider objects need to be properly registered in the= service container with the ezpublish.location_view_provider<= /strong> or ezpublish.content_view_provider service tag.

=20
parameters:
    acme.location_view_provider.class: Acme\DemoBundle\Content\MyLocationVi=
ewProvider

services:
    acme.location_view_provider:
        class: %ezdemo.location_view_provider.class%
        tags:
            - {name: ezpublish.location_view_provider, priority: 30}

=20
Tag attribute name Usage
priority

An integer giving the priority to the <= span>View\Provider\(Content|Location) in the View\Manag= er.

The priority range is from -255 to 255

Example

Custom View\Provider\Location
=20
<?php

namespace Acme\DemoBundle\Content;

use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\MVC\Symfony\View\Provider\Location as LocationViewProvi=
der;
use eZ\Publish\API\Repository\Values\Content\Location;

class MyLocationViewProvider implements LocationViewProvider
{
    /**
     * Returns a ContentView object corresponding to $location, or void if =
not applicable
     *
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
     * @param string $viewType
     * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView|null
     */
    public function getView( Location $location, $viewType )
    {
        // Let's check location Id
        switch ( $location->id )
        {
            // Special template for home page, passing "foo" variable to th=
e template
            case 2:
                return new ContentView( "AcmeDemoBundle:$viewType:home.html=
.twig", array( 'foo' =3D> 'bar' ) );
        }
 
        // ContentType identifier (formerly "class identifier")
        switch ( $contentInfo->contentType->identifier )
        {
            // For view full, it will load AcmeDemoBundle:full:small_folder=
.html.twig
            case 'folder':
                return new ContentView( "AcmeDemoBundle:$viewType:small_fol=
der.html.twig" );
        }
    }
}
=20

 

------=_Part_4025_95895776.1485856404658--