Skip to the content
Documentation

ez_is_field_empty: comparison of v.2 vs v.3

No ratings yet

Versions Compared

Old Version 2

changes.mady.by.user André Rømcke

Saved on Dec 30, 2016

compared with

New Version Current

changes.mady.by.user André Rømcke

Saved on Dec 31, 2016

Key

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

Comment: correct type hint on API and not internal implementation

Description

ez_is_field_empty() is a Twig helper which checks if a Content item's field value is considered empty in the current language.

It returns a boolean value (true or false).

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

Prototype and Arguments

ez_is_field_empty( eZ\Publish\CoreAPI\Repository\Values\Content\Content content, eZ\Publish\API\Repository\Values\Content\Field|string fieldDefIdentifier[, string forcedLanguage] )

Argument name Type Description
content eZ\Publish\CoreAPI\Repository\Values\Content\Content Content object the displayable field belongs to.
fieldDefIdentifier eZ\Publish\API\Repository\Values\Content\Field or string The field we want to check or its identifier.
forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Usage

Using the Field identifier as parameter
Code Block
language html/xml
{# Display "description" field if not empty #}
{% if not ez_is_field_empty( content, "description" ) %}
    <div class="description">
        {{ ez_render_field( content, "description" ) }}
    </div>
{% endif %}
Using the Field as parameter
Code Block
language html/xml
{# Display "description" field if not empty #}
{% if not ez_is_field_empty( content, field ) %}
    <div class="description">
        {{ ez_render_field( content, field.fieldDefIdentifier ) }}
    </div>
{% endif %}
Checking if field exists before use
Code Block
language html/xml
{# Display "description" field if it exists and is not empty #}
{% if content.fields.description is defined and not ez_is_field_empty( content, "description" ) %}
    <div class="description">
        {{ ez_render_field( content, "description" ) }}
    </div>
{% endif %}

 

Comments

Add a comment

Comments are read by a moderator before they appear.