twig tutorial - Accessing variables in Twig - twig php - twig template
Accessing variables
- In Twig templates variables can be accessed using double curly braces notation {{ variableName }}.
Basic example of greeting user
Accessing array elements
- Twig as a parameter can receive array. To access a specific element of array you can use regular php array access bracket notation {{ array[key] }}.
Previous example modified to use array as a parameter
Accessing object properties
- Objects also can be passed as a parameter to template. 'Dot' (.) notation is used to access specific object properties {{ object.propertyName }}.
Same example with object as a parameter