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

Skip to end of metadata
Go to start of metadata

Description

ez_render_field() is a Twig helper allowing to display a Content item's Field value, taking advantage of the template block exposed by the FieldType used.

Template blocks for built-in FieldTypes reside in EzPublishCoreBundle.

Prototype and Arguments

ez_render_field( eZ\Publish\Core\Repository\Values\Content\Content content, string fieldDefinitionIdentifier[, hash params)

Argument nameTypeDescription
contenteZ\Publish\Core\Repository\Values\Content\ContentContent object the displayable field belongs to.
fieldDefinitionIdentifierstringThe identifier the Field is referenced by.
paramshash

Hash of parameters that will be passed to the template block.

By default you can pass 2 entries:

  • lang (to override the current language, must be a valid locale with xxx-YY format)
  • template (to override the template to use, see below)
  • attr (hash of HTML attributes you want to add to the inner markup)
  • parameters (arbitrary parameters to pass to the template block)
Some FieldTypes might expect specific entries under the parameters key, like the Map Location field type

Override a field template block

In some cases, you may not want to use the built-in field template block as it might not fit your markup needs. In this case, you can choose to override the template block to use by specifying your own template. You can do this inline when calling ez_render_field(), or globally by prepending a field template to use by the helper.

Your template block must comply to a regular FieldType template block, as explained in the FieldType documentation.

Inline override

You can easily use the template you need by filling the template entry in the params argument.

The code above will load my_field_template.html.twig located in AcmeTestBundle/Resources/views/fields/.

Overriding a block and calling the parent

When overriding a field template block, it is possible to call the "parent" one. For this, you need to import original template horizontally, using use Twig tag.

 

Inline override using current template

Version compatibility

Inline override using current template is possible as of 5.2 / 2013.11

 

If you want to override a specific field template only once (i.e. because your override would be only valid in your current template), you can specify the current template to be the source of the field block.

Inline override using current template

Limitation

Using _self will only work if your current template is extending another one.

This is basically the same limitation than for Symfony form themes.

 

Global override

In the case where you want to systematically reuse a field template instead of the default one, you can append it to the field templates list to use by ez_render_field().

To make your template available, you must register it to the system.

ezpublish/config/ezpublish.yml

You can define these rules in a dedicated file instead of ezpublish/config/ezpublish.yml. Read the cookbook recipe to learn more about it.