Attributes and dot notation
This page is for designers who read values from nodes, objects and hashes. The dot is the template language's one way to look inside a value.
Contents
Objects, hashes and arrays
$node.name {* attribute of an object *}
$settings.color {* key of a hash *}
$items.0.name {* first item of an array, then its attribute *}Kernel objects (nodes, objects, attributes, users) expose a fixed list of attributes; a node, for example, has name,
url_alias, data_map, children, parent, path, class_identifier, can_edit and more
(Nodes, objects and attributes).
Chains
$node.data_map.image.content['large'].url
$node.object.owner.name
$node.parent.nameEach step is a lookup; some (like children or parent) run a database query. Store a value you use several times
in a variable.
Dynamic keys
When the key is in a variable, use brackets:
def $field = 'intro'
$node.data_map[$field].has_content
$image_content[$image_class].urlWhat does this object have?
The attribute and dump operators print the attributes of a value (lib/eztemplate/classes/eztemplateattributeoperator.php):
$node|attribute( show, 1 )
$node.data_map|dump( show, 2 )show prints values too; the number is the depth. Use them only on a test siteaccess and remove them before
committing: they print internal data.
Missing attributes
Reading an attribute that does not exist prints nothing and writes a warning to the debug output. Test optional values first:
if is_set( $node.data_map.subtitle ).../if
if $node.data_map.image.has_content.../ifRelated pages
- TPL syntax basics
- Nodes, objects and attributes
- Template debugging
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.