Skip to the content
Documentation

Injecting parameters in content views: comparison of v.4 ...

No ratings yet

Versions Compared

Old Version 4

changes.mady.by.user Dominika Kurek

Saved on May 17, 2016

compared with

New Version Current

changes.mady.by.user Dominika Kurek

Saved on Jun 22, 2016

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Comment: link corrected

Description

It is possible to dynamically inject variables in content view templates by listening to the  exponential.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
language php
<?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
title Service 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: exponential.pre_content_view, method: onPreContentView}

 

 

In this topic:
Table of Contents
maxLevel 3
Related topics:

Content Rendering

Configuration: Default view templates todelete

Comments

Add a comment

Comments are read by a moderator before they appear.