General

  eZ Systems Website
  Editor documentation


  Developer documentation

  Back to the top

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: correct type hint on API and not internal implementation

Description

ez_trans_prop() is a generic, low level Twig helper which corrects gets the translated value of a multi valued(translations) property.

Info
If the current language cannot be found as a translation for content, the main language (see further down for details) will be used if this is supported by the provided object. This behavior is identical when forcing a language using forcedLanguage.

Prototype and Arguments

ez_trans_prop( ValueObject object, string property[, string forcedLanguage)

Argument nameTypeDescription
objecteZ\Publish\CoreAPI\Repository\Values\ValueObjectValueObject object property belongs to.
propertystringProperty to get translated value from, logic is using one of the following (in this order):
  • object method "get{property}" 
  • object property  "{property}s"
forcedLanguagestringOptional language we want to force (e.g. "eng-US"), otherwise takes prioritized languages from SiteAccess settings.
Main language use

Main language is attempted to be applied in the following way for Value objects that support this:

  • When attribute is retrieved via object property: Use mainLanguageCode property if it exists as fallback language, but only if either alwaysAvailable property does not exists or is true.
  • When attribute is retrieved via object method: Provide $language = null as the only argument to the method, depends on logic of ValueObject if this gives a fallback value or not

Usage of ez_trans_prop

Example below shows how this function can be used to get the Content name with exact same result as using ez_content_name(content)

Code Block
{{ ez_trans_prop( versionInfo, "name" ) }}

Example for ContentType->names:

Code Block
{{ ez_trans_prop( contentType, "name" ) }}