Message-ID: <406265109.3252.1485852521379.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3251_605385237.1485852521379" ------=_Part_3251_605385237.1485852521379 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=  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

 

Related topics:=
------=_Part_3251_605385237.1485852521379--