Command reference - Tree navigation | Portal Scripting Interface
The Content, Layout, and Portlet beans each represent a tree hierarchy. The basic navigation methods are the same for all three. A tree bean provides methods to access the root node to look up the parent and children of a node, and to maintain a cursor that points to a selected node in the tree.
The code examples use the Content bean, but we can do the same operations on the other tree beans as well. The command root returns the ID of the root node, as a fixed starting point for navigation.
Jython: Content.root()
Jacl: $Content root
We can select a node by its ID using the select command. We can clear the current selection by using deselect or by using select without an argument. We can return the ID of the selected node using the current command. For interactive use, csn is an alias for current. Jython example:
user = "SiteAdmin" pwd = "SiteAdmin" Portal.login(user, pwd) #Content.select ID Content.deselect Content.current Content.csn # example: select the root node Content.select(Content.root()) print Content.select(Content.root())Jacl example:$Content select ID $Content deselect $Content current $Content csn # example: select the root node $Content select [$Content root]The path command returns a list of all IDs from the root to the currently selected node. In a similar way, the children command returns the children of the selected node. We can obtain the ID of the parent of the selected node by using parent. Jython example:
user = "SiteAdmin" pwd = "SiteAdmin" Portal.login(user, pwd) Content.path Content.parent Content.children print " " print "Node Z6_00000000000000A0BR2B300GO2 has has children" Content.select("Z6_00000000000000A0BR2B300GO2") for child in Content.children().split(): print child print " " print "Node Z6_00000000000000A0BR2B300SJ0 has no children" for child in Content.select("Z6_00000000000000A0BR2B300SJ0").split(): { Content.details(child) }Jacl example:$Portal login SiteAdmin SiteAdmin $Content path $Content parent $Content children # example: select a node and print its children $Content select Z6_00000000000000A0BR2B300SJ0 foreach child [$Content children] { puts "$child" }We can also use the commands path, parent, and children with an explicit ID instead of implicitly referring to the currently selected node. Jython example:
user = "SiteAdmin" pwd = "SiteAdmin" Portal.login(user, pwd) Content.path("Z6_00000000000000A0BR2B300GO2") Content.parent("Z6_00000000000000A0BR2B300GO2") Content.children("Z6_00000000000000A0BR2B300GO2") print Content.path("Z6_00000000000000A0BR2B300GO2") print Content.parent("Z6_00000000000000A0BR2B300GO2") print Content.children("Z6_00000000000000A0BR2B300GO2")Jacl example:$Content path ID $Content parent ID $Content children IDFor simplicity, there are dedicated select commands for the root node and for the parent of the currently selected node. In the following example, the first argument is a dummy used to distinguish the method from the select with an ID argument. The dummy argument is not interpreted. The second argument is a keyword, which is not case-sensitive. Alternative, shorter keywords are documented in the bean help. Jython example:
Content.select("the", "root") Content.select("the", "parent")Jacl example:$Content select the root $Content select the parent
Parent topic: Command reference for the Portal Scripting Interface