Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Attribute and dump operators

attribute and dump from eZTemplateAttributeOperator - listing what an object, a hash or an array offers to templates, with or without values, to a depth, as an HTML table or as text, and why their output must never…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/template-operators/attribute-and-dump-operators.md

On this page

Attribute and dump operators

When you do not know what a variable holds, attribute and dump list it. Both are registered by eZTemplateAttributeOperator (lib/eztemplate/classes/eztemplateattributeoperator.php) through lib/eztemplate/classes/eztemplateautoload.php. They walk arrays and every object that has the attributes() and attribute() methods (nodes, content objects, attributes, users and the other persistent objects), one level per step, and print one line per key.

The output is produced by a formatter chosen in template.ini:

[AttributeOperator]
DefaultFormatter=html
OutputFormatter[html]=ezpAttributeOperatorHTMLFormatter
OutputFormatter[text]=ezpAttributeOperatorTextFormatter

ezpAttributeOperatorManager::getOutputFormatter() (kernel/private/eztemplate/ezpattributeoperatormanager.php) falls back to DefaultFormatter for a name that is not registered. An extension can add a formatter class that implements ezpAttributeOperatorFormatterInterface and list it under OutputFormatter[].

Contents

  1. attribute
  2. dump
  3. Safety
  4. Related pages

attribute

attribute

Lists the keys of the piped array or object, by default without values and two levels deep.

ParameterTypeRequiredDefault
show_valuesstring: show to include valuesno'' (names and types only)
max_valnumber: levels to descendno2
formathtml or textno[AttributeOperator] DefaultFormatter

Input: the value to inspect, piped. Returns the formatted listing; a scalar or an empty array is returned as the formatter exports it. Generated reference: attribute.

The fields of the Fit & Healthy front page (node 89), one level, as text:

{def $node = fetch( 'content', 'node', hash( 'node_id', 89 ) )}
{$node.data_map|attribute( 'show', 1, 'text' )}

Output:

title (object[eZContentObjectAttribute]=Object)
metadata (object[eZContentObjectAttribute]=Object)
teaser_title (object[eZContentObjectAttribute]=Object)
teaser_intro (object[eZContentObjectAttribute]=Object)
full_intro (object[eZContentObjectAttribute]=Object)
image (object[eZContentObjectAttribute]=Object)
tags (object[eZContentObjectAttribute]=Object)

Without show, only names and types:

{def $hash = hash( 'title', 'Fit & Healthy', 'tags', array( 'fit', 'healthy' ) )}
{$hash|attribute( '', 2, 'text' )}

Output:

title (string)
tags (array)
    0 (string)
    1 (string)

dump

dump

The same walk with other defaults: values shown, one level deep.

ParameterTypeRequiredDefault
show_valuesstring: show to include valuesno'show'
max_valnumber: levels to descendno1
formathtml or textno[AttributeOperator] DefaultFormatter

Generated reference: dump.

{def $hash = hash( 'title', 'Fit & Healthy', 'tags', array( 'fit', 'healthy' ) )}
{$hash|dump( 'show', 2, 'text' )}

Output:

title (string='Fit & Healthy')
tags (array=Array(2))
    0 (string='fit')
    1 (string='healthy')

With the default formatter, html, the result is a table:

{hash( 'node_id', 89, 'name', 'Fit & Healthy' )|dump}

Output:

<table><tr><th align="left">Attribute</th>
<th align="left">Type</th>
<th align="left">Value</th>
</tr>
<tr><td>node_id</td>
<td>integer</td>
<td>89</td>
</tr>
<tr><td>name</td>
<td>string</td>
<td>'Fit & Healthy'</td>
</tr>
</table>

A scalar comes back as it was:

[{'plain text'|dump( 'show', 1, 'text' )}] [{42|attribute( 'show', 1, 'text' )}]

Output:

['plain text'] [42]

Safety

  • The HTML formatter does not escape values: 'Fit & Healthy' above came out with a bare &. A value that holds markup or script is printed as it is. Use these operators on a development installation, or inside a block that only administrators see, and remove them before a template goes live.
  • A deep level on a node walks into its object, its versions, its parents and their attributes: every level multiplies the number of database queries. Start with max_val 1.
  • Some attributes are computed when they are read. Listing them with values runs that code, so a dump can be slow even when the page is small.

The examples were rendered by the interpreter and again with the template compiler on a development installation; both gave the same output.

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x