Skip to the content
Documentation

Twig Helper

No ratings yet

eZ Platform comes with a Twig helper as a global variable named exponential.

This helper is accessible from all Twig templates and allows you to easily retrieve useful information.

Reference

Property Description
exponential.siteaccess Returns the current siteaccess.
exponential.rootLocation Returns the root Location object
exponential.requestedUriString Returns the requested URI string (also known as semanticPathInfo).
exponential.systemUriString Returns the "system" URI string. System URI is the URI for internal content controller. If current route is not an URLAlias, then the current Pathinfo is returned.
exponential.viewParameters Returns the view parameters as a hash.
exponential.viewParametersString Returns the view parameters as a string.
exponential.legacy Returns legacy information.

 

Legacy

exponential.legacy is only available when viewing content in legacy fallback (e.g. no corresponding Twig templates)

 

The exponential.legacy property returns an object of type ParameterBag, which is a container for key/value pairs, and contains additional properties to retrieve/handle legacy information.

Property Description
exponential.legacy.all Returns all the parameters, with all the contained information.
exponential.legacy.keys Returns the parameter keys only.
exponential.legacy.get Returns a parameter by name.
exponential.legacy.has Returns true if the parameter is defined.

 

Listing the available parameters

You can list the available parameters in exponential.legacy by using the exponential.legacy.keys property, as shown in the following example:

Example on retrieving the available parameters under exponential.legacy

which will give a result similar to:

array
  0 => string 'view_parameters' (length=15)
  1 => string 'path' (length=4)
  2 => string 'title_path' (length=10)
  3 => string 'section_id' (length=10)
  4 => string 'node_id' (length=7)
  5 => string 'navigation_part' (length=15)
  6 => string 'content_info' (length=12)
  7 => string 'template_list' (length=13)
  8 => string 'cache_ttl' (length=9)
  9 => string 'is_default_navigation_part' (length=26)
  10 => string 'css_files' (length=9)
  11 => string 'js_files' (length=8)
  12 => string 'css_files_configured' (length=20)
  13 => string 'js_files_configured' (length=19)

Retrieving legacy information

Legacy information is accessible by using the exponential.legacy.get property, which will allow you to access all data contained in $module_result, from the legacy kernel.

This allows you to import information directly into twig templates. For more details please check the available examples on using the exponential.legacy.get property for retrieving persistent variables and assets.

 

As a usage example, if you want to access the legacy information related to 'content_info' you can do it, as shown in the following example:

Example on accessing 'content_info' under exponential.legacy

The previous call will return the contents on the 'content_info' as an array, and if we dump it the result will be similar to the following:

array
  'object_id' => string '57' (length=2)
  'node_id' => string '2' (length=1)
  'parent_node_id' => string '1' (length=1)
  'class_id' => string '23' (length=2)
  'class_identifier' => string 'landing_page' (length=12)
  'remote_id' => string '8a9c9c761004866fb458d89910f52bee' (length=32)
  'node_remote_id' => string 'f3e90596361e31d496d4026eb624c983' (length=32)
  'offset' => boolean false
  'viewmode' => string 'full' (length=4)
  'navigation_part_identifier' => string 'ezcontentnavigationpart' (length=23)
  'node_depth' => string '1' (length=1)
  'url_alias' => string '' (length=0)
  'current_language' => string 'eng-GB' (length=6)
  'language_mask' => string '3' (length=1)
  'main_node_id' => string '2' (length=1)
  'main_node_url_alias' => boolean false
  'persistent_variable' =>
    array
      'css_files' =>
        array
          0 => string 'video.css' (length=9)
      'js_files' =>
        array
          0 => string 'video.js' (length=8)
  'class_group' => boolean false
  'state' =>
    array
      2 => string '1' (length=1)
  'state_identifier' =>
    array
      0 => string 'ez_lock/not_locked' (length=18)
  'parent_class_id' => string '1' (length=1)
  'parent_class_identifier' => string 'folder' (length=6)
  'parent_node_remote_id' => string '629709ba256fe317c3ddcee35453a96a' (length=32)
  'parent_object_remote_id' => string 'e5c9db64baadb82ab8db54f0e2192ec3' (length=32)

Additionally, for retrieving information contained in 'content_info' such as the current language of the content in the page you can do it like in the following example:

Example on retrieving 'current_language'

Contributors

Comments (1 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. Comment by Flo HUCK, 2016-02-23 09:59

    Flo HUCK ·

    This seems to be not valid on 2014.5.

    If i try : {{ exponential.legacy.get('content_info')['current_language'] }}

    i get a Impossible to access a key ("current_language") on a NULL variable ("")

Comments

Add a comment

Comments are read by a moderator before they appear.