Forums / Developer / How can find a user groups grandparent?

How can find a user groups grandparent?

Author Message

Brendan Pike

Thursday 28 October 2004 2:40:02 am

How can I find the grandparent of a users usergroup? I did find the below article but I wasn't able to convert it for my need. Any help much appreciated.

http://ez.no/ez_publish/documentation/incoming/how_to_find_the_parent_and_grandparent_of_an_object

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

Hans Melis

Thursday 28 October 2004 3:17:37 am

Hi Brendan,

The article you linked to takes a rather large detour to find the grandparent of a node. The following code snippet should give you the grandparent:

{$node.parent.parent}

If you want the object, it's similar to accessing the object of the current node

{let grandparent=$node.parent.parent}
  {$grandparent.object|attribute(show)}
{/let}

hth

Hans
http://blog.hansmelis.be

Brendan Pike

Thursday 28 October 2004 5:53:09 am

Thanks Hans
Doesn't work for me though, I'm inside the edit_attribute.tpl This works for me

group_id=$current_user.contentobject.main_parent_node_id

But this is only the parent not grandparent of course. Any other ideas?

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

Hans Melis

Thursday 28 October 2004 8:38:33 am

Aha, you want it directly for a user. You need an additional fetch then.

{let parentNode=fetch('content','node',hash('node_id',$current_user.contentobject.main_parent_node_id))
     grandparent=$parentNode.parent}
{$grandparent.name|wash}
{/let}

Once you have a node, it's similar to what I wrote in my first reply. If you have an object (like $current_user.contentobject), then you need to find a node first.

Hans
http://blog.hansmelis.be

Brendan Pike

Thursday 28 October 2004 9:03:27 am

Nope your code still didn't work for me :(
Just got the following errors,
Unknown template variable 'parentNode' in namespace ''
Unknown template variable 'grandparent' in namespace ''
The mystery continues

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

Hans Melis

Thursday 28 October 2004 9:07:48 am

You're using a namespace then. Try using $: instead of just $ in front of the variables.

Hans
http://blog.hansmelis.be

Brendan Pike

Thursday 28 October 2004 9:27:17 am

Yup your right, think I'd better go to bed.

Works nicely now, many thanks :-)

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.