5

Lets say I have a simple string:

{% set string = "Simple String" %}

How to get number of characters of my string?

8

Twig has a length filter that can help you with that:

{% set stringLength = "Simple String" | length %}

Note that this also works on arrays to give you the number of items in the array.

2

If you are attempting to get a count of the string, you can use Twigs dump function.

{{ dump(myString) }}

  • This only works in devMode from what I've read. Never tried it outside of devMode, though. – Bill Criswell Jun 14 '14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.