ez.no / exponential / documentation / reference / template operators / miscellaneous / attribute
$input|attribute( [show_values [, level [, table ] ] ] )
| Name | Type | Description | Required |
|---|---|---|---|
| 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 |
string containing description of input array/hash/object.
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.
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'
Log in or create a user account to comment.
Comments