Jump to main content Jump to doc navigation

modX::lexicon

Returns a processed Lexicon entry.

The method itself always returns a string or null. The property $modx->lexicon of the same name holds the modLexicon service object — PHP allows a property and a method to share a name.

Syntax

string|null lexicon (string $key, [array $params = array()], [string $language = ''])
  • $key (string) lexicon key. required
  • $params (array) values substituted into the placeholders of the entry
  • $language (string) language key; the cultureKey value is used by default.

Returns the translated string. Returns null if the entry does not exist or the lexicon service has not been initialized. In that case the log gets a “Culture not initialized; cannot use lexicon.” error.

Example

Output the translation of the welcome_message entry with the name Placeholder filled in:

echo $modx->lexicon('welcome_message', array('name' => 'John'), 'en');

The example assumes a lexicon entry with a name placeholder:

$_lang['welcome_message'] = 'Hello [[+name]]!  How are you today?';

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more