ez_content_name: comparison of v.1 vs v.2
Versions Compared
Old Version 1
changes.mady.by.user Dominika Kurek
Saved on Jul 08, 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.
Description
ez_content_name() is a Twig helper which allows displaying a Content item's name in the current language.
| Info |
|---|
| If the current language cannot be found as a translation for content, the name in the main language is always returned. This behavior is identical when forcing a language. |
Prototype and Arguments
ez_content_name( eZ\Publish\CoreAPI\Repository\Values\Content\Content content[, string forcedLanguage] )
ez_content_name(contentInfo[, string forcedLanguage] )
| Argument name | Type | Description |
|---|---|---|
| content |
eZ\Publish\CoreAPI\Repository\Values\Content\Content or eZ\Publish\CoreAPI\Repository\Values\Content\ContentInfo |
Content or ContentInfo object the displayable field belongs to. |
| forcedLanguage | string | Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) |
Usage
| Code Block |
|---|
<h2>Content name in current language: {{ ez_content_name( content ) }}</h2>
<h2>Content name in current language, from ContentInfo: {{ ez_content_name( content.contentInfo ) }}</h2>
<h2>Content name in french (forced): {{ ez_content_name( content, "fre-FR" ) }}</h2>
|
Equivalent PHP code
Getting the translated name for a Content item
| Code Block | ||
|---|---|---|
|
||
// Assuming we're in a controller action $translationHelper = $this->get( 'exponential.translation_helper' ); // From Content $translatedContentName = $translationHelper->getTranslatedContentName( $content ); // From ContentInfo $translatedContentName = $translationHelper->getTranslatedContentNameByContentInfo( $contentInfo ); |
Forcing a specific language
| Code Block | ||
|---|---|---|
|
||
// Assuming we're in a controller action $translatedContentName = $this->get( 'exponential.translation_helper' )->getTranslatedName( $content, 'fre-FR' ); |
Comments
Add a comment