attribute

Summary

Prints keys, attribute names, methods and values available in an object/array/hash.

Usage

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

Parameters

NameTypeDescriptionRequired
show_values string Show values in addition to keys, names, etc. no
level integer Number of levels/children to show. Default is 2. no
table boolean Return result as HTML table or not. Default is true. no

Returns

string containing description of input array/hash/object.

Description

This operator prints all available keys, attribute names and/or methods in an object, and array or a hash. Only the array keys and object attribute names are shown by default. By passing "show" as the first parameter, the operator will also display the values. The second parameter can be used to control the number of levels/children that should be expanded and displayed. The default setting is 2. Be careful with large values for level
as this may result in problems with values that loop. The returned result is an HTML table containing the collected information. If "false()" is passed as the third parameter the output will be a plain string instead of an HTML table.

The input must be either an array, an object or a hash.

This operator is very handy when it comes to debugging and creation of new template code. For example, this operator is often used to display the attributes of a node. This can be done by doing a {$node|attribute(show)} from within a template where the $node variable is available.

Examples

Example 1

{let my_array=hash('Name', 'John Doe', 'Age', 24, 'Phone', '555-3212')}

{$my_array|attribute()}

{/let}

returns the following:

Attribute    Type

Name        string

Age         integer

Phone number string

Example 2

{let my_array=hash('Name', 'John Doe', 'Age', 24, 'Phone', '555-3212')}

{$my_array|attribute(show)}

{/let}

returns the following:

Attribute    Type    Value

Name        string 'John Doe'

Age         integer 24

Phone number string '555-3212'

Comments

Log in or create a user account to comment.

Contents

Reference

Database diagram
Template operators
    PDF
    Arrays
    Data extraction
    Formatting
    Images
    Logic
    Mathematics
    Miscellaneous
       month_overview
       attribute
       treemenu
    Strings
    URLs
    Variables
Template functions
Data fetching
Modules
XML tags


Created

05/02/2004
11:50:40 am
by Balazs Halasy

Last updated

13/05/2004
9:09:13 pm
by Paul Borgermans

Authors

Balazs Halasy
Kåre Køhler Høvik
Paul Borgermans



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.