{foreach $all_child_nodes as $key=>$child_node} {*append all the child node to an array*} {set $children_node_arr=$children_node_arr|append($child_node.node_id)} {if$child_node.is_main} {if count($child_node.object.assigned_nodes)|eq(2)} {foreach $child_node.object.assigned_nodes as $tmp_node} {if $child_node.node_id|eq($tmp_node.node_id)|not} {set $user_group_array=$user_group_array|append($tmp_node.parent)} {set $user_group_array=$user_group_array|append($tmp_node.parent)} {/if} {/foreach} {/if} {else} {set $user_group_array=$user_group_array|append($child_node.main_node.parent)} {/if} {/foreach}