Is there a difference between using single-quoted and double-quoted strings?


There is a small difference, single-quoted strings don't support interpolation:

{% set string = 'There is a #{car}.' %}

The above example won't work. If you want to use it, you need to wrap your string in double quotes:

{% set string = "There is a #{car}." %}
  • 1
    This is similar to the PHP logic between single and double quotes.
    – Lindsey D
    Jun 16 '14 at 22:16
  • Except that you can concatenate string in PHP using single quotes (using "."). Twig still requires double quotes (using "~"). Jun 17 '14 at 11:22
  • 3
    @Bryan {{ 'test' ~ 'String' }} works for me.
    – carlcs
    Jun 25 '14 at 15:06
  • @ChristianSeelbach Yep. You're right. I misread the Twig docs. Jun 25 '14 at 15:14

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.