I want to concatenate 3 variables in one bracket, like PHP.
i.e
In PHP:
getimagesize($path.$image)
We can concatenate variables with dot notation. How can I reproduce this in twig?
{{ path.key }}
isn't working as intended.
Twig provides two ways to combine strings together: You can concatenate them using the tilde ( ~ ) operator, or you can inject a string into the middle of another string using string interpolation.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect.
In PowerShell, string concatenation is primarily achieved by using the “+” operator. There are also other ways like enclosing the strings inside double quotes, using a join operator, or using the -f operator.
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.
Use the tilde character ~
to concatenate string and/or variables.
~: Converts all operands into strings and concatenates them. {{ "Hello " ~ name ~ "!" }} would return (assuming name is 'John') Hello John!.
Read about it in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With