Skip to the content
Documentation

Array and object inspection

No ratings yet

While you write a template you often need to know what a variable holds: which attributes a node has, which keys an array has, what an attribute's content is. Two operators print it: attribute and dump. Use them during development only and remove them before the template goes live: their output can reveal data a visitor should not see.

attribute

attribute prints a table of the keys or attribute names of an array or object. Its first parameter, 'show', adds the values; the second sets how many levels deep it goes (2 when left out):

{$node|attribute( 'show', 1 )}
{$node.object|attribute( 'show', 1 )}
{$node.data_map|attribute( 'show', 1 )}

The first line lists the node's attributes (node_id, name, url_alias, children_count, object, data_map and the rest) with their types and values. The last line lists the content attributes of the node's object by their identifiers, which is how you find the names to use in $node.​data_​map.​<identifier>.

dump

dump does the same with other defaults: it shows the values, goes one level deep, and also prints plain values such as strings, numbers and null:

{$view_parameters|dump}
{$node.data_map.title.content|dump}

Both print HTML tables by default; a third parameter, 'text', prints plain text instead, for a template that is not HTML. Details: attribute, dump.

Without touching the template

Every attribute of a node and of an object, with what it costs to read, is listed in the template language manual: node attributes, object attributes and content attributes by datatype. Large objects can make attribute slow with a deep level, because reading some attributes runs database queries; start with level 1.

To see which templates a page used and which variables went into them, use the Exp Debug bar (see Debugging templates).

Contributors

Comments (1 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. Doesn't show simple values anymore

    Olav Bringedal ·

    If you use attribute(show) to show a non-array or object like {$node.node_id|attribute(show)} it outputs nothing. A bit irritating when you crawl down an object in search for a value, and when you think you have found it it shows nothing :)
    I'm pretty sure it did so in 3.5

Comments

Add a comment

Comments are read by a moderator before they appear.