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}." %}


Looking at the Twig code, they have this documented for the “same as” test: Checks if a variable is the same as another one (=== in PHP). I won’t re-hash the details of === vs. == in PHP because there is an excellent comparison here: https://stackoverflow.com/questions/80646/how-do-the-php-equality-double-equals-and-identity-triple-equals-comp The money ...


They're both the same for the most part. The only time I'd use the second way you listed is when the property is a variable. For instance: {% set foo = 'name' %} {{ variable[foo] }} This will give you {{ variable.name }}


Generally speaking, no. They are just two ways of saying the same thing. Dot syntax is necessary when you are referring to a method within an object. However, if you are only trying to access the property of an object (or a value within an array), either technique will work.


For example: false == 0 will be true false === 0 will be false It is very useful when you use such functions as file_put_contents() and preg_match(). The first function returns a number of bytes writtent to the file (which can be 0 if nothing was written what does not mean that it's false). And the second one returns 1 if something was found otherwise 0....

Only top voted, non community-wiki answers of a minimum length are eligible