i’working on a project php/twig and i got problem in my template while calling the split function of Twig
here is my admin.twig
{% set safeties = ["allg", "labor", "s1"] %}
{% set suArrRequire = ("1" ~ data.pflichtSU)|split('') %}
{% for safety in safeties %}
<div class="col-xs-4 col-sm-3">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary radio-inline {% if suArrRequire[loop.index0] == 1 %}active{% endif %}" for="yes{{ loop.index0 }}">
<input type="radio" name="data[suRequire][{{ safety }}]" id="yes{{ loop.index0 }}" value="1" autocomplete="off" {% if suArrRequire[loop.index0] == 1 %}checked{% endif %}><span class="tr" key="yes"></span>
</label>
<label class="btn btn-secondary radio-inline {% if suArrRequire[loop.index0] == 0 %}active{% endif %}" for="no{{ loop.index0 }}">
<input type="radio" name="data[suRequire][{{ safety }}]" id="no{{ loop.index0 }}" value="0" autocomplete="off" {% if suArrRequire[loop.index0] == 0 %}checked{% endif %}><span class="tr" key="no"></span>
</label>
</div>
</div>
{% endfor %}
</div>
and here is the function from Twig class CoreExtension.php:
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
{
if (strlen($delimiter) > 0) {
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
}
if ($limit <= 1) {
return preg_split('/(?<!^)(?!$)/u', $value);
}
$length = mb_strlen($value, $env->getCharset());
if ($length < $limit) {
return [$value];
}
$r = [];
for ($i = 0; $i < $length; $i += $limit) {
$r[] = mb_substr($value, $i, $limit, $env->getCharset());
}
return $r;
}
public function getFilters(): array
{
return [
// formatting filters
new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]),
new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
new TwigFilter('format', 'sprintf'),
new TwigFilter('replace', 'twig_replace_filter'),
new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
new TwigFilter('abs', 'abs'),
new TwigFilter('round', 'twig_round'),
// encoding
new TwigFilter('url_encode', 'twig_urlencode_filter'),
new TwigFilter('json_encode', 'json_encode'),
new TwigFilter('convert_encoding', 'twig_convert_encoding'),
// string filters
new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]),
new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]),
new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]),
new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]),
new TwigFilter('striptags', 'strip_tags'),
new TwigFilter('trim', 'twig_trim_filter'),
new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]),
// array helpers
new TwigFilter('join', 'twig_join_filter'),
new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]),
new TwigFilter('sort', 'twig_sort_filter'),
new TwigFilter('merge', 'twig_array_merge'),
new TwigFilter('batch', 'twig_array_batch'),
new TwigFilter('column', 'twig_array_column'),
new TwigFilter('filter', 'twig_array_filter'),
new TwigFilter('map', 'twig_array_map'),
new TwigFilter('reduce', 'twig_array_reduce'),
// string/array filters
new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]),
new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]),
new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]),
new TwigFilter('first', 'twig_first', ['needs_environment' => true]),
new TwigFilter('last', 'twig_last', ['needs_environment' => true]),
// iteration and runtime
new TwigFilter('default', '_twig_default_filter', ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', 'twig_get_array_keys_filter'),
];
}
the Error i get is
enter image description here
i tried to wrok on the parametrs but still get the same problem