Array and object inspection

By using the "attribute" template operator, it is possible to quickly inspect the contents of arrays and template objects. The operator creates an overview of available keys, attribute names and/or methods in an object or an array. By default, only the array keys and object attribute names (also called identifiers) are shown. 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 will be explored (the default setting is 2). The following example demonstrates how the operator can be used to inspect the contents of an "ezcontentobjecttreenode" object.

{$node|attribute( show, 1 )}

The following output will be produced:

Attribute

Type

Value

node_id

string

2

parent_node_id

string

1

main_node_id

string

2

contentobject_id

string

1

contentobject_version

string

10

contentobject_is_published

string

1

depth

string

1

sort_field

string

8

sort_order

string

1

priority

string

 

modified_subnode

string

1108118324

path_string

string

'/1/2/'

path_identification_string

string

''

is_hidden

string

 

is_invisible

string

 

name

string

'eZ publish'

data_map

array

Array(6)

object

object[ezcontentobject]

Object

subtree

array

Array(114)

children

array

Array(44)

children_count

string

44

contentobject_version_object

object[ezcontentobjectversion]

Object

sort_array

array

Array(1)

can_read

boolean

true

can_create

boolean

false

can_edit

boolean

false

can_hide

boolean

false

can_remove

boolean

false

can_move

boolean

false

creator

object[ezcontentobject]

Object

path

array

Array(0)

path_array

array

Array(2)

parent

object[ezcontentobjecttreenode]

Object

url

string

''

url_alias

string

''

class_identifier

string

'folder'

class_name

string

'Folder'

hidden_invisible_string

string

'-/-'

hidden_status_string

string

'Visible'

As the output shows, there is a lot of information that can be extracted from a node object. In addition to strings and numbers the object also consists of other objects. For example, the creator of the node is a "ezcontentobject" object. The creator object can be further inspected by doing the following:

{$node.creator|attribute( show, 1 )}

The following output will be produced:

Attribute

Type

Value

id

string

14

section_id

string

2

owner_id

string

14

contentclass_id

string

4

name

string

'Administrator User'

is_published

string

 

published

string

1033920830

modified

string

1033920830

current_version

string

1

status

string

1

current

object[ezcontentobjectversion]

Object

versions

array

Array(1)

author_array

array

Array(1)

class_name

string

'User'

content_class

object[ezcontentclass]

Object

contentobject_attributes

array

Array(5)

owner

object[ezcontentobject]

Object

related_contentobject_array

array

Array(0)

related_contentobject_count

string

 

reverse_related_contentobject_array

array

Array(0)

reverse_related_contentobject_count

string

 

can_read

boolean

false

can_create

boolean

false

can_create_class_list

array

Array(0)

can_edit

boolean

false

can_translate

boolean

false

can_remove

boolean

false

can_move

boolean

false

data_map

array

Array(5)

main_parent_node_id

string

13

assigned_nodes

array

Array(1)

parent_nodes

array

Array(1)

main_node_id

string

15

main_node

object[ezcontentobjecttreenode]

Object

default_language

string

'eng-GB'

content_action_list

boolean

false

class_identifier

string

'user'

class_group_id_list

array

Array(1)

name

string

'Administrator User'

match_ingroup_id_list

boolean

false

Again, this object consists of a lot of information. As mentioned above, the "attribute" operator can be used on both objects and arrays. The following example demonstrates how to inspect the "data_map" array (which reveals the object's attributes) of the node's creator object.

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

The following output will be produced:

Attribute

Type

Value

first_name

object[ezcontentobjectattribute]

Object

last_name

object[ezcontentobjectattribute]

Object

user_account

object[ezcontentobjectattribute]

Object

signature

object[ezcontentobjectattribute]

Object

image

object[ezcontentobjectattribute]

Object

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.