Message-ID: <614198280.3058.1485851810779.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3057_1352791698.1485851810779" ------=_Part_3057_1352791698.1485851810779 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Parameters injection in content views

Parameters injection in content views

It is possible to dynamically inject variables in content view t= emplates by listening to the ezpublish.pre_content_view<= /strong> event.

The event listener method receives an eZ\Publish\Core\MVC\Sym= fony\Event\PreContentViewEvent object

Example

The following example will inject foo and osTypes variables in all content view templates.

=20
<?php

namespace Acme\DemoBundle\EventListener;
use eZ\Publish\Core\MVC\Symfony\Event\PreContentViewEvent;

class PreContentViewListener
{
    public function onPreContentView( PreContentViewEvent $event )
    {
        // Get content view object and inject whatever no need.
        // You may add some custom business logic here.
        $contentView =3D $event->getContentView();
        $contentView->addParameters(
            array(
                 'foo'          =3D> 'bar',
                 'osTypes'      =3D> array( 'osx', 'linux', 'win' )
            )
        );
    }
}
=20
Service configuration
=20
parameters:
    ezdemo.pre_content_view_listener.class: Acme\DemoBundle\EventListener\P=
reContentViewListener

services:
    ezdemo.pre_content_view_listener:
        class: %ezdemo.pre_content_view_listener.class%
        tags:
            - {name: kernel.event_listener, event: ezpublish.pre_content_vi=
ew, method: onPreContentView}

=20

 

 

------=_Part_3057_1352791698.1485851810779--