str()
Twig Function
Functions prefixed with str_ perform tasks that are useful when dealing with strings. The helper maps directly to the Str PHP class and its methods. For example:
___TWIG0___
The above is the PHP equivalent of the following:
<?= Str::camel() ?>
Methods in camelCase should be converted to snake_case.
You may also apply the string functions as a Twig filter.
___TWIG0___
# str_limit()
Limit the number of characters in a string.
___TWIG0___
To add a suffix when limit is applied, pass it as the third argument. Defaults to ....
___TWIG0___
# str_words()
Limit the number of words in a string.
___TWIG0___
To add a suffix when limit is applied, pass it as the third argument. Defaults to ....
___TWIG0___
# str_replace
Replace all occurrences of the search string with the replacement string.
// Outputs: Bob
___TWIG0___
# str_camel()
Convert a value to camelCase.
// Outputs: helloWorld
___TWIG0___
# str_studly()
Convert a value to StudlyCase.
// Outputs: HelloWorld
___TWIG0___
# str_snake()
Convert a value to snake_case.
// Outputs: hello_world
___TWIG0___
The second argument can supply a delimiter.
// Outputs: hello---world
___TWIG0___
# str_plural()
Gets the plural form of an English word.
// Outputs: chickens
___TWIG0___
# str_upper()
Makes a string uppercase.
// Outputs: Hello I'm JACK
Hello I'm ___TWIG0___
# str_lower()
Makes a string lowercase.
// Outputs: Hello I'm jack
Hello I'm ___TWIG0___
# str_ucfirst()
Makes a string's first character uppercase.
// Outputs: Hello I'm Jack
Hello I'm ___TWIG0___
# str_lcfirst()
Makes a string's first character lowercase.
// Outputs: Hello I'm jack
Hello I'm ___TWIG0___
# str_repeat()
Repeats a string.
// Outputs: We are the best best best!
We are the ___TWIG0___!
# str_pad_both
Pads a string to a certain length with another string from both sides.
// Outputs: ooxxxoo
___TWIG0___
# str_pad_left
Pads a string to a certain length with another string from left side.
// Outputs: ooxxx
___TWIG0___
# str_pad_right
Pads a string to a certain length with another string from right side.
// Outputs: xxxoo
___TWIG0___
# str_reverse
Reverses a string.
// Outputs: !dlrow olleH
___TWIG0___