XF 2.2 Use $xf.language.language_code in template with substr

mcatze

Well-known member
Hey guys,

i want to use the {$xf.language.language_code}, but not the full string of en-US. I need at first just en and secondly just US as string.

Is there a way how to make it in the template?
 
We support substr in templates. Assuming every language code has two characters separated by a hyphen followed by two characters:

Code:
en = {$xf.language.language_code|substr(0, 2)}
<br /><br />
US = {$xf.language.language_code|substr(3, 2)}
 
This sounds great. I didn't know that substr is supported. Thanks for your quick reply. (y)
 
This sounds great. I didn't know that substr is supported. Thanks for your quick reply. (y)
The $defaultFilters array in \XF\Template\Templater.php is a goldmine - check it out :)
PHP:
    protected $defaultFilters = [
        'default'          => 'filterDefault',
        'censor'           => 'filterCensor',
        'count'            => 'filterCount',
        'currency'         => 'filterCurrency',
        'emoji'            => 'filterEmoji',
        'escape'           => 'filterEscape',
        'for_attr'         => 'filterForAttr',
        'file_size'        => 'filterFileSize',
        'first'            => 'filterFirst',
        'format'           => 'filterFormat',
        'hex'              => 'filterHex',
        'host'             => 'filterHost',
        'htmlspecialchars' => 'filterHtmlspecialchars',
        'ip'               => 'filterIp',
        'join'             => 'filterJoin',
        'json'             => 'filterJson',
        'last'             => 'filterLast',
        'nl2br'            => 'filterNl2Br',
        'nl2nl'            => 'filterNl2Nl',
        'number'           => 'filterNumber',
        'number_short'     => 'filterNumberShort',
        'numeric_keys_only' => 'filterNumericKeysOnly',
        'pad'              => 'filterPad',
        'parens'           => 'filterParens',
        'pluck'            => 'filterPluck',
        'preescaped'       => 'filterPreEscaped',
        'raw'              => 'filterRaw',
        'replace'          => 'filterReplace',
        'split'            => 'filterSplit',
        'split_long'       => 'filterSplitLong',
        'strip_tags'       => 'filterStripTags',
        'to_lower'         => 'filterToLower',
        'to_upper'         => 'filterToUpper',
        'de_camel'         => 'filterDeCamel',
        'substr'           => 'filterSubstr',
        'url'              => 'filterUrl',
        'urlencode'        => 'filterUrlencode',
        'zerofill'         => 'filterZeroFill',
    ];
 
Back
Top Bottom