Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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\Symfony\Event\PreContentViewEvent object

Example

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

Code Block
languagephp
<?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 = $event->getContentView();
        $contentView->addParameters(
            array(
                 'foo'          => 'bar',
                 'osTypes'      => array( 'osx', 'linux', 'win' )
            )
        );
    }
}
Code Block
titleService configuration
parameters:
    ezdemo.pre_content_view_listener.class: Acme\DemoBundle\EventListener\PreContentViewListener

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