How can I count a multivalue field's values in twig? I want to count the number of values of unlimited field in twig tempalate I tried

{{ node.field_mytext.count }}  => faced with error

and  in another try 

{{ content.field_mytext.count }} => nothing returned     

(in this method I checked my field is not in disabled field is display manager).



My question is how can I count the number of items of a field in Twig?

I hope I face with the solutions expect these solutions :D   


add it in preprocess_node
use Twig Tweak
{{ node.field_mytext.count }} => faced with error

This does not work, because the method count is not allowed in twig policies:


  core/lib/Drupal/Core/Template/TwigSandboxPolicy.php


{{ content.field_mytext | length }}?

This does not work, because content is a render array with a lot of additional keys.

This works: Convert field to array and count    

{{ node.field_mytext.getvalue | length }}