in the getting started tour of Symfony2 i came across this:
{# array('user' => array('name' => 'Fabien')) #}
{{ user.name }}
{# force array lookup #}
{{ user['name'] }}
{# array('user' => new User('Fabien')) #}
{{ user.name }}
{{ user.getName }}
{# force method name lookup #}
{{ user.name() }}
{{ user.getName() }}
Can someone explain me the difference?
In twig when you just use
foo.bar,foomay be an array (in this case twig expects a keybar), or an object, whereas it expects either a accessible propertybar, a methodsgetBar(), and I guess something I forgot. However, the point is, that twig tries to resolve the kind of access itself and you can throw in, whatever you like (beside that it must obviously in a form of structured data). If you use a specific access method, you take the ability to guess from twig: When you callfoo.bar()it’s obviously a method. (Must say, that I never heard of “forced lookup” :X)