11

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

1 Answer 1

18

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}." %}
4
  • 1
    This is similar to the PHP logic between single and double quotes.
    – Lindsey D
    Commented Jun 16, 2014 at 22:16
  • Except that you can concatenate string in PHP using single quotes (using "."). Twig still requires double quotes (using "~"). Commented Jun 17, 2014 at 11:22
  • 3
    @Bryan {{ 'test' ~ 'String' }} works for me.
    – carlcs
    Commented Jun 25, 2014 at 15:06
  • @ChristianSeelbach Yep. You're right. I misread the Twig docs. Commented Jun 25, 2014 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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