CRUDlex\TwigExtensions

class TwigExtensions

Provides and setups the Twig extensions like filters.

formatTime($value, $timezone, $pattern)

Formats the given time value to a timestring defined by the $pattern parameter.

If the value is false (like null), an empty string is returned. Else, the value is tried to be parsed as datetime via the given pattern. If that fails, it is tried to be parsed with the pattern ‘Y-m-d H:i:s’. If that fails, the value is returned unchanged. Else, it is returned formatted with the given pattern. The effect is to shorten ‘Y-m-d H:i:s’ to ‘Y-m-d’ for example.

Parameters:
  • $value (string) – the value to be formatted
  • $timezone (string) – the timezone of the value
  • $pattern (string) – the pattern with which the value is parsed and formatted
Returns:

string the formatted value

registerTwigExtensions(Container $app)

Registers all extensions.

Parameters:
  • $app (Container) – the current application
getLanguageName($language)

Gets a language name in the given language.

Parameters:
  • $language (string) – the language code of the desired language name
Returns:

string the language name in the given language or null if not available

formatFloat($float)

Formats a float to not display in scientific notation.

Parameters:
  • $float (float) – the float to format
Returns:

double|string the formated float

formatDate($value, $isUTC)

Formats the given value to a date of the format ‘Y-m-d’.

Parameters:
  • $value (string) – the value, might be of the format ‘Y-m-d H:i’ or ‘Y-m-d’
  • $isUTC (boolean) – whether the given value is in UTC
Returns:

string the formatted result or an empty string on null value

formatDateTime($value, $isUTC)

Formats the given value to a date of the format ‘Y-m-d H:i’.

Parameters:
  • $value (string) – the value, might be of the format ‘Y-m-d H:i’
  • $isUTC (boolean) – whether the given value is in UTC
Returns:

string the formatted result or an empty string on null value