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

Injecting parameters in content views

=20
=20
=20
=20

Description

It is possible to dynamically inject variables in content view templates= 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

 

 

=20
=20
=20
=20

In this topic:

Related topics:=

Content Rendering

Default view templates

=20
=20
=20
------=_Part_2773_1248033704.1485850759569--