Message-ID: <1415141232.4454.1485866533953.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4453_1193900770.1485866533953" ------=_Part_4453_1193900770.1485866533953 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Twig Helper

Twig Helper

eZ Publish 5.1 comes with a Twig helper as a global variable named ezpu= blish.

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

Reference

Property Description
ezpublish.siteaccess

Returns the current siteaccess.

ezpublish.requestedUriString= Returns the requested URI string (= also known as semanticPathInfo).
ezpublish.systemUriString Returns the "system" URI string. S= ystem URI is the URI for internal content controller. If current route is n= ot an URLAlias, then the current Pathinfo is returned.
ezpublish.viewParameters Returns the view parameters as a h= ash.
ezpublish.viewParametersStri= ng Returns the view parameters as a s= tring.
ezpublish.legacy Returns legacy information.

 

Legacy

The ezpublish.legacy property returns an object of type&nbs= p;ParameterBag,= which is a container for key/value pairs, and contains additional properti= es to retrieve/handle legacy information.

Property Description
ezpublish.legacy.all Returns all the parameters, with all the contain= ed information.
ezpublish.legacy.keys<= /td> Returns the parameter keys only.
ezpublish.legacy.get Returns a parameter by name.
ezpublish.legacy.has Returns true if the parameter is defined.

 

Listing the available p= arameters

You can list the available parameters in ezpublish.legacy b= y using the ezpublish.legacy.keys property, as shown in the fo= llowing example:

Example on retrieving the available parameters under ezpublish.legacy
=20
{{ dump(ezpublish.legacy.keys()) }}
=20

which will give a result similar to:

=20
array
  0 =3D> string 'view_parameters' (length=3D15)
  1 =3D> string 'path' (length=3D4)
  2 =3D> string 'title_path' (length=3D10)
  3 =3D> string 'section_id' (length=3D10)
  4 =3D> string 'node_id' (length=3D7)
  5 =3D> string 'navigation_part' (length=3D15)
  6 =3D> string 'content_info' (length=3D12)
  7 =3D> string 'template_list' (length=3D13)
  8 =3D> string 'cache_ttl' (length=3D9)
  9 =3D> string 'is_default_navigation_part' (length=3D26)
  10 =3D> string 'css_files' (length=3D9)
  11 =3D> string 'js_files' (length=3D8)
  12 =3D> string 'css_files_configured' (length=3D20)
  13 =3D> string 'js_files_configured' (length=3D19)
=20

Retrieving legacy informa= tion

Legacy information is accessible by using the ezpublish.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 ezpubli= sh.legacy.get property for retrieving persiste= nt variables and assets.


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

Example on accessing 'content_info' under ezpublish.legacy
=20
{{ ezpublish.legacy.get('content_info') }}
=20

The previous call will return the contents on the 'content_info' as an <= code>array, and if we dump it the result will be simila= r to the following:

=20
array
  'object_id' =3D> string '57' (length=3D2)
  'node_id' =3D> string '2' (length=3D1)
  'parent_node_id' =3D> string '1' (length=3D1)
  'class_id' =3D> string '23' (length=3D2)
  'class_identifier' =3D> string 'landing_page' (length=3D12)
  'remote_id' =3D> string '8a9c9c761004866fb458d89910f52bee' (length=3D3=
2)
  'node_remote_id' =3D> string 'f3e90596361e31d496d4026eb624c983' (lengt=
h=3D32)
  'offset' =3D> boolean false
  'viewmode' =3D> string 'full' (length=3D4)
  'navigation_part_identifier' =3D> string 'ezcontentnavigationpart' (le=
ngth=3D23)
  'node_depth' =3D> string '1' (length=3D1)
  'url_alias' =3D> string '' (length=3D0)
  'current_language' =3D> string 'eng-GB' (length=3D6)
  'language_mask' =3D> string '3' (length=3D1)
  'main_node_id' =3D> string '2' (length=3D1)
  'main_node_url_alias' =3D> boolean false
  'persistent_variable' =3D>=20
    array
      'css_files' =3D>=20
        array
          0 =3D> string 'video.css' (length=3D9)
      'js_files' =3D>=20
        array
          0 =3D> string 'video.js' (length=3D8)
  'class_group' =3D> boolean false
  'state' =3D>=20
    array
      2 =3D> string '1' (length=3D1)
  'state_identifier' =3D>=20
    array
      0 =3D> string 'ez_lock/not_locked' (length=3D18)
  'parent_class_id' =3D> string '1' (length=3D1)
  'parent_class_identifier' =3D> string 'folder' (length=3D6)
  'parent_node_remote_id' =3D> string '629709ba256fe317c3ddcee35453a96a'=
 (length=3D32)
  'parent_object_remote_id' =3D> string 'e5c9db64baadb82ab8db54f0e2192ec=
3' (length=3D32)
=20

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

Example on retrieving 'current_language'
=20
{{ ezpublish.legacy.get('content_info')['current_language'] }}=20
------=_Part_4453_1193900770.1485866533953--