Gkphp/Library/Traits/Psr0/Twig/Twig/ExtensionCore.php

Classes

Twig_Extension_Core

Functions

twig_cycle()

twig_cycle(\ArrayAccess|array  $values, integer  $position) : string

Cycles over a value.

Parameters

\ArrayAccess|array $values
integer $position

The cycle position

Returns

string —

The next value in the cycle

twig_random()

twig_random(\Twig_Environment  $env, \Traversable|array|integer|float|string  $values = null) : mixed

Returns a random value depending on the supplied parameter type: - a random item from a Traversable or array - a random character from a string - a random integer between 0 and the integer parameter.

Parameters

\Twig_Environment $env
\Traversable|array|integer|float|string $values

The values to pick a random item from

Throws

\Twig_Error_Runtime

when $values is an empty array (does not apply to an empty string which is returned as is)

Returns

mixed —

A random value from the given sequence

twig_date_format_filter()

twig_date_format_filter(\Twig_Environment  $env, \DateTimeInterface|\DateInterval|string  $date, string|null  $format = null, \DateTimeZone|string|false|null  $timezone = null) : string

Converts a date to the given format.

  {{ post.published_at|date("m/d/Y") }}

Parameters

\Twig_Environment $env
\DateTimeInterface|\DateInterval|string $date

A date

string|null $format

The target format, null to use the default

\DateTimeZone|string|false|null $timezone

The target timezone, null to use the default, false to leave unchanged

Returns

string —

The formatted date

twig_date_modify_filter()

twig_date_modify_filter(\Twig_Environment  $env, \DateTimeInterface|string  $date, string  $modifier) : \DateTimeInterface

Returns a new date object modified.

  {{ post.published_at|date_modify("-1day")|date("m/d/Y") }}

Parameters

\Twig_Environment $env
\DateTimeInterface|string $date

A date

string $modifier

A modifier string

Returns

\DateTimeInterface —

A new date object

twig_date_converter()

twig_date_converter(\Twig_Environment  $env, \DateTimeInterface|string|null  $date = null, \DateTimeZone|string|false|null  $timezone = null) : \DateTime

Converts an input to a DateTime instance.

   {% if date(user.created_at) < date('+2days') %}
     {# do something #}
   {% endif %}

Parameters

\Twig_Environment $env
\DateTimeInterface|string|null $date

A date or null to use the current time

\DateTimeZone|string|false|null $timezone

The target timezone, null to use the default, false to leave unchanged

Returns

\DateTime —

A DateTime instance

twig_replace_filter()

twig_replace_filter(string  $str, array|\Traversable  $from) : string

Replaces strings within a string.

Parameters

string $str

String to replace in

array|\Traversable $from

Replace values

Returns

string

twig_round()

twig_round(integer|float  $value, integer|float  $precision, string  $method = 'common') : integer|float

Rounds a number.

Parameters

integer|float $value

The value to round

integer|float $precision

The rounding precision

string $method

The method to use for rounding

Returns

integer|float —

The rounded number

twig_number_format_filter()

twig_number_format_filter(\Twig_Environment  $env, mixed  $number, integer  $decimal = null, string  $decimalPoint = null, string  $thousandSep = null) : string

Number format filter.

All of the formatting options can be left null, in that case the defaults will be used. Supplying any of the parameters will override the defaults set in the environment object.

Parameters

\Twig_Environment $env
mixed $number

A float/int/string of the number to format

integer $decimal

the number of decimal points to display

string $decimalPoint

the character(s) to use for the decimal point

string $thousandSep

the character(s) to use for the thousands separator

Returns

string —

The formatted number

twig_urlencode_filter()

twig_urlencode_filter(string|array  $url) : string

URL encodes (RFC 3986) a string as a path segment or an array as a query string.

Parameters

string|array $url

A URL or an array of query parameters

Returns

string —

The URL encoded value

twig_array_merge()

twig_array_merge(array|\Traversable  $arr1, array|\Traversable  $arr2) : array

Merges an array with another one.

 {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}

 {% set items = items|merge({ 'peugeot': 'car' }) %}

 {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #}

Parameters

array|\Traversable $arr1

An array

array|\Traversable $arr2

An array

Returns

array —

The merged array

twig_slice()

twig_slice(\Twig_Environment  $env, mixed  $item, integer  $start, integer  $length = null, boolean  $preserveKeys = false) : mixed

Slices a variable.

Parameters

\Twig_Environment $env
mixed $item

A variable

integer $start

Start of the slice

integer $length

Size of the slice

boolean $preserveKeys

Whether to preserve key or not (when the input is an array)

Returns

mixed —

The sliced variable

twig_first()

twig_first(\Twig_Environment  $env, mixed  $item) : mixed

Returns the first element of the item.

Parameters

\Twig_Environment $env
mixed $item

A variable

Returns

mixed —

The first element of the item

twig_last()

twig_last(\Twig_Environment  $env, mixed  $item) : mixed

Returns the last element of the item.

Parameters

\Twig_Environment $env
mixed $item

A variable

Returns

mixed —

The last element of the item

twig_join_filter()

twig_join_filter(array  $value, string  $glue = '', string|null  $and = null) : string

Joins the values to a string.

The separators between elements are empty strings per default, you can define them with the optional parameters.

 {{ [1, 2, 3]|join(', ', ' and ') }}
 {# returns 1, 2 and 3 #}

 {{ [1, 2, 3]|join('|') }}
 {# returns 1|2|3 #}

 {{ [1, 2, 3]|join }}
 {# returns 123 #}

Parameters

array $value

An array

string $glue

The separator

string|null $and

The separator for the last pair

Returns

string —

The concatenated string

twig_split_filter()

twig_split_filter(\Twig_Environment  $env, string  $value, string  $delimiter, integer  $limit = null) : array

Splits the string into an array.

 {{ "one,two,three"|split(',') }}
 {# returns [one, two, three] #}

 {{ "one,two,three,four,five"|split(',', 3) }}
 {# returns [one, two, "three,four,five"] #}

 {{ "123"|split('') }}
 {# returns [1, 2, 3] #}

 {{ "aabbcc"|split('', 2) }}
 {# returns [aa, bb, cc] #}

Parameters

\Twig_Environment $env
string $value

A string

string $delimiter

The delimiter

integer $limit

The limit

Returns

array —

The split string as an array

twig_get_array_keys_filter()

twig_get_array_keys_filter(array  $array) : array

Returns the keys for the given array.

It is useful when you want to iterate over the keys of an array:

 {% for key in array|keys %}
     {# ... #}
 {% endfor %}

Parameters

array $array

An array

Returns

array —

The keys

twig_reverse_filter()

twig_reverse_filter(\Twig_Environment  $env, array|\Traversable|string  $item, boolean  $preserveKeys = false) : mixed

Reverses a variable.

Parameters

\Twig_Environment $env
array|\Traversable|string $item

An array, a Traversable instance, or a string

boolean $preserveKeys

Whether to preserve key or not

Returns

mixed —

The reversed input

twig_sort_filter()

twig_sort_filter(array|\Traversable  $array) : array

Sorts an array.

Parameters

array|\Traversable $array

Returns

array

twig_trim_filter()

twig_trim_filter(  $string,   $characterMask = null,   $side = 'both') : string

Returns a trimmed string.

Parameters

$string
$characterMask
$side

Throws

\Twig_Error_Runtime

When an invalid trimming side is used (not a string or not 'left', 'right', or 'both')

Returns

string

twig_escape_filter()

twig_escape_filter(\Twig_Environment  $env, mixed  $string, string  $strategy = 'html', string  $charset = null, boolean  $autoescape = false) : string

Escapes a string.

Parameters

\Twig_Environment $env
mixed $string

The value to be escaped

string $strategy

The escaping strategy

string $charset

The charset

boolean $autoescape

Whether the function is called by the auto-escaping feature (true) or by the developer (false)

Returns

string

twig_convert_encoding()

twig_convert_encoding(  $string,   $to,   $from) 

Parameters

$string
$to
$from

twig_length_filter()

twig_length_filter(\Twig_Environment  $env, mixed  $thing) : integer

Returns the length of a variable.

Parameters

\Twig_Environment $env

A Twig_Environment instance

mixed $thing

A variable

Returns

integer —

The length of the value

twig_upper_filter()

twig_upper_filter(\Twig_Environment  $env, string  $string) : string

Converts a string to uppercase.

Parameters

\Twig_Environment $env
string $string

A string

Returns

string —

The uppercased string

twig_lower_filter()

twig_lower_filter(\Twig_Environment  $env, string  $string) : string

Converts a string to lowercase.

Parameters

\Twig_Environment $env
string $string

A string

Returns

string —

The lowercased string

twig_title_string_filter()

twig_title_string_filter(\Twig_Environment  $env, string  $string) : string

Returns a titlecased string.

Parameters

\Twig_Environment $env
string $string

A string

Returns

string —

The titlecased string

twig_capitalize_string_filter()

twig_capitalize_string_filter(\Twig_Environment  $env, string  $string) : string

Returns a capitalized string.

Parameters

\Twig_Environment $env
string $string

A string

Returns

string —

The capitalized string

twig_test_empty()

twig_test_empty(mixed  $value) : boolean

Checks if a variable is empty.

{# evaluates to true if the foo variable is null, false, or the empty string #}
{% if foo is empty %}
    {# ... #}
{% endif %}

Parameters

mixed $value

A variable

Returns

boolean —

true if the value is empty, false otherwise

twig_test_iterable()

twig_test_iterable(mixed  $value) : boolean

Checks if a variable is traversable.

{# evaluates to true if the foo variable is an array or a traversable object #}
{% if foo is iterable %}
    {# ... #}
{% endif %}

Parameters

mixed $value

A variable

Returns

boolean —

true if the value is traversable

twig_include()

twig_include(\Twig_Environment  $env, array  $context, string|array  $template, array  $variables = array(), boolean  $withContext = true, boolean  $ignoreMissing = false, boolean  $sandboxed = false) : string

Renders a template.

Parameters

\Twig_Environment $env
array $context
string|array $template

The template to render or an array of templates to try consecutively

array $variables

The variables to pass to the template

boolean $withContext
boolean $ignoreMissing

Whether to ignore missing templates or not

boolean $sandboxed

Whether to sandbox the template or not

Returns

string —

The rendered template

twig_source()

twig_source(\Twig_Environment  $env, string  $name, boolean  $ignoreMissing = false) : string

Returns a template content without rendering it.

Parameters

\Twig_Environment $env
string $name

The template name

boolean $ignoreMissing

Whether to ignore missing templates or not

Returns

string —

The template source

twig_constant()

twig_constant(string  $constant, object|null  $object = null) : string

Provides the ability to get constants from instances as well as class/global constants.

Parameters

string $constant

The name of the constant

object|null $object

The object to get the constant from

Returns

string

twig_constant_is_defined()

twig_constant_is_defined(string  $constant, object|null  $object = null) : boolean

Checks if a constant exists.

Parameters

string $constant

The name of the constant

object|null $object

The object to get the constant from

Returns

boolean

twig_array_batch()

twig_array_batch(array  $items, integer  $size, mixed  $fill = null) : array

Batches item.

Parameters

array $items

An array of items

integer $size

The size of the batch

mixed $fill

A value used to fill missing items

Returns

array