function twig_slice

Slices a variable.

Parameters

Twig_Environment $env A Twig_Environment instance:

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):

Return value

mixed The sliced variable

2 calls to twig_slice()
twig_first in drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php
Returns the first element of the item.
twig_last in drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php
Returns the last element of the item.
1 string reference to 'twig_slice'
Twig_Extension_Core::getFilters in drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php
Returns a list of filters to add to the existing list.

File

drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php, line 621

Code

function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) {
  if ($item instanceof Traversable) {
    $item = iterator_to_array($item, false);
  }
  if (is_array($item)) {
    return array_slice($item, $start, $length, $preserveKeys);
  }
  $item = (string) $item;
  if (function_exists('mb_get_info') && null !== ($charset = $env
    ->getCharset())) {
    return mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset);
  }
  return null === $length ? substr($item, $start) : substr($item, $start, $length);
}