Skip to the content
Documentation

ez_field_value

No ratings yet

AVAILABLE AS OF 5.2 / 2013.09

Description

ez_field_value() is a Twig helper which returns a Content item's field value in the current language.

This can be useful when you don't want to use ez_render_field and manage the rendering by yourself.

If the current language cannot be found as a translation for content, main language will be used. This behavior is identical when forcing a language using forcedLanguage.

Prototype and Arguments

ez_field_value( eZ\Publish\Core\Repository\Values\Content\Content content, string fieldDefIdentifier[, string forcedLanguage] )

Argument name Type Description
content eZ\Publish\Core\Repository\Values\Content\Content Content object the field referred to with fieldDefIdentifier belongs to.
fieldDefIdentifier string Identifier of the field we want to get the value from.
forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Usage

 

 

 

 

Contributors

Comments (1 historical)

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

  1. Comment by Jani Tarvainen, 2015-11-04 08:55

    Jani Tarvainen ·

    To check the existence of a specific field you can use Twig in eZ Platform:

    {% if content.fields.cool_field is defined %}
        This content has a cool_field field!
    {% else %}
        This content does NOT have a cool_field field!
    {% endif %}

    Kudos to Edi Modric for the tip, I was wasting time with this.

Comments

Add a comment

Comments are read by a moderator before they appear.