Forums / Developer / Template variables - parent_node_id in adding new content

Template variables - parent_node_id in adding new content

Author Message

Sao Tavi

Sunday 29 May 2011 10:16:00 am

When adding a new element in front end (so not from admin control panel) I need to access the id of that element's parent (I created a new datatype that needs to care about this info).

It should be something like $module_result.parent_node_id. The bad part is that $module_result seems not to be set, neither $pagedata or other things I tried.

Niko Goers

Sunday 29 May 2011 11:26:51 am

Hi Sao,

try this:

 $object.current.main_parent_node_id

It should work.

The most interesting variables in /content/edit are $object and $content_attributes I would say.

eZ Publish partner - http://www.all2e.com
http://share.ez.no/directory/companies/all2e-gmbh
http://ez.no/Partners/all2e-GmbH

Lords of Heaven - http://www.LoH-Gilde.de (Created with eZ Publish)
German online gaming guild

About me - http://www.NikoGoers.de

My roadmap, +1 are welcome: http://share.ez.no/community/roadmap/10889

Sao Tavi

Sunday 29 May 2011 12:13:40 pm

Thank you for your reply, Niko

Unfortunately, that did not work. Also

     {foreach $object as $item}
        {$item} az
        {/foreach}

Returned nothing, not even the az that would say that it went through the loop. On the other hand, not even the $pagedesign variable is not set, and it is used for sure in the display of the page.

So... my conclusion is that almost no variables are set before creating the form, and that is in the core of eZ, so I cannot change the location where to create it.

On the other hand, I just found where I can set template variables in php. Is there any global that knows the page id or the parent id?

Or is it possible to be a scope change, so that I cannot access the variables set before?

Sao Tavi

Sunday 29 May 2011 2:00:49 pm

Oh, well, it seems there is a magical attribute_edit_gui that is blocking all the variables except the mentioned ones. One more step, it seems...

Marko Žmak

Sunday 29 May 2011 4:11:28 pm

Hi Sao, just a few suggetions:

  • try using $object.current.temp_main_node
  • try using {$object|attribute(show)} and look at the output you get
  • you can pass parameters to attribute_edit_gui the same way you pass it to {include}, for example like this: {attribute_edit_gui attribute=myattribute some_parameter='some_value'}. After that, you can use this parameter in the attribute edit gui template like this: $#ContentAttribute:some_parameter
  • you can use this parameters/variables also in the templates that are included from the attribute edit gui template, like for example the embed template for an object inside an XML Block attribute

Hope some of this helps.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Sao Tavi

Sunday 29 May 2011 4:45:47 pm

Thank you, Marko, that attribute(show) seems to be really useful. I was wondering how to get a print_r in the template engine :D

I managed to finish the editing part of this datatype. This datatype should create a common relation between 2 objects, one of them being the parent of the object that contains this datatype. Also, one object cannot have 2 children that connect to the same other object, nor have a child that connects to him. This is the part that I managed to do so far.

The problem now is that also the other object should know of this relation (so not only the object that has the child with this datatype). One way to achieve this is by automatically creating a child at the other object that will have a relation with the first object.

Is there any other way to do this? Is it possible to get the list of objects that connect to a specific object? I am using the same connection type as object relation datatype (I actually got the code from there, I just edited it a little bit to suit my needs).

Nicolas Pastorino

Tuesday 31 May 2011 12:30:04 am

Hi Sao, Marko, Niko,

An interesting blog-post + discussion by Steven, you should have a look at this : http://share.ez.no/blogs/steven-e.-bailey/wherefore-art-thou-data (discussion here)

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye