ibexa

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

attribute

Summary

Makes it possible to inspect the contents of arrays, hashes and objects.

Usage

input|attribute( [show_values [, level [, table ] ] ] )

Parameters

NameTypeDescriptionRequired
show_values string Extract values in addition to keys, names, etc. No.
level integer The number of levels that should be processed (default is 2). No.
table boolean Return result as HTML table (default) or not. No.

Returns

A string revealing information about the target.

Description

This operator extracts all available keys, attribute names and/or methods that belong to the input parameter (must be either an object, an array or a hash). By default, only the array keys and object attribute names will be revealed. By passing "show" as the first parameter, the operator will also return the values. The second parameter can be used to control the number of levels/children that should be expanded and included in the result (the default setting is 2). A large level value may cause the system to be trapped in a recursive/infinite loop. The returned result is an HTML table containing the retrieved information. If "false()" is passed as the third parameter, the output will be a plain string instead of an HTML table. Please refer to the "Array and object inspection" section of the "Templates" chapter for more information about the use of this operator.

Examples

Example 1

{def $example=hash( 'Name',  'John Doe',
                    'Age',   24,
                    'Phone', '555-3212' )}
 
{$example|attribute()}

The following output will be produced:

Attribute

Type

Name

string

Age

integer

Phone

string

Example 2

{def $example=hash( 'Name',  'Jane Doe',
                    'Age',   23,
                    'Phone', '555-3213' )}
 
{$example|attribute( 'show' )}

The following output will be produced:

Attribute

Type

Value

Name

string

'Jane Doe'

Age

integer

23

Phone

string

'555-3213'

Balazs Halasy (05/02/2004 10:50 am)

Balazs Halasy (04/05/2005 2:24 pm)


Comments

  • Infinite loop bomb warning

    Be warned that this operator will enter an infinite loop in some cases, even when used with depth level 1. This is because certain object attributes refer to their parents. For instance, using it with the "data_map" member of most ez objects is one sure way to cause an infinite loop. The page on which you try to use a template containing this will never finish loading, and you'll get a HTTP server process consuming a lot of CPU for a while, depending on the server settings. You may need to restart the HTTP server or kill the offending process by hand.