twig_test_empty example

return $r;
}

// The '_default' filter is used internally to avoid using the ternary operator // which costs a lot for big contexts (before PHP 5.4). So, on average, // a function call is cheaper. /** * @internal */
function _twig_default_filter($value$default = '')
{
    if (twig_test_empty($value)) {
        return $default;
    }

    return $value;
}

/** * 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 %} * * @param array $array An array * * @return array The keys */
                    $label = $arguments[1];
                    $variables = $arguments[2] ?? null;
                    $lineno = $label->getTemplateLine();

                    if ($label instanceof ConstantExpression) {
                        // If the label argument is given as a constant, we can either                         // strip it away if it is empty, or integrate it into the array                         // of variables at compile time.                         $labelIsExpression = false;

                        // Only insert the label into the array if it is not empty                         if (!twig_test_empty($label->getAttribute('value'))) {
                            $originalVariables = $variables;
                            $variables = new ArrayExpression([]$lineno);
                            $labelKey = new ConstantExpression('label', $lineno);

                            if (null !== $originalVariables) {
                                foreach ($originalVariables->getKeyValuePairs() as $pair) {
                                    // Don't copy the original label attribute over if it exists                                     if ((string) $labelKey !== (string) $pair['key']) {
                                        $variables->addElement($pair['value']$pair['key']);
                                    }
                                }
                            }
Home | Imprint | This part of the site doesn't use cookies.