Simple check if form field has errors in Twig template

后端 未结 10 1638
一个人的身影
一个人的身影 2021-01-30 08:11

In Twig template I check if a field has an error like this:

{% if form.points.get(\'errors\') is not empty %}

Is there any method like:

10条回答
  •  粉色の甜心
    2021-01-30 09:09

    i have create a twig extension to handle this: my extension

    public function hasError($string)
    {
        if(strlen($string) > 4)
            return true;
        return false;
    }
    

    i use it like this in twig

    {{ has_error(form_errors(form.username)) ? form_errors(form.username) : '' }}
    

提交回复
热议问题