Forums / Setup & design / If object isn't in current folder searhc parent

If object isn't in current folder searhc parent

Author Message

Stephen Przepiora

Tuesday 09 March 2004 8:12:53 pm

I am trying to figure out a way to return a peice of content from the current folder, and if that doesn't exist look higher in the path. Is there a way to do that?

Alex Jones

Wednesday 10 March 2004 6:57:15 am

Yes, it is possible, and there is probably more than one way to do it. Pretty much what you will want to do is write a section tag that checks to see if your content is empty or not. If it is empty then you do a fetch against the parent node and display it's content. Here is some code (untested, you may need to tweak):

{section show=ne($:item.data_map.body,'')} {* check to see if the body is _not_ empty *}
  {attribute_view_gui attribute=$:item.data_map.body}
{section-else} {* body is empty so grab content from the parent *}
  {let name=Child children=fetch('content','list',hash(parent_node_id,$node.parent_node_id,))}
    {attribute_view_gui attribute=$:item.data_map.body}
  {/let}
{/section}

If nothing else, you would do well to look at the attributes available to you by adding <i>{$node|attribute(show)}</i> to the template, which will provide you a table of the information that applies to that object. From there you can easily figure out what to use in your template to display the attribute in question. From the documentation (http://ez.no/ez_publish/documentation/development/libraries/ez_template/operators/miscellaneous):

<b>attribute</b>
Helper attribute to print available methods in objects and arrays, by default it only shows the array keys and object attribute names but by passing show as parameter it will fetch the values.

The second parameter can be used to controlled the number of children to expand, default is no limit which may give problems with values that loop. The returned result is an HTML table unless false() is passed as the third parameter. E.g.

{$node|attribute(show)}, {$node|attribute(show,2,false)}

Hope this helps.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Stephen Przepiora

Wednesday 10 March 2004 1:29:30 pm

Is there any way to continue on higher in the directory stucture until you find a piece of content?

Alex Jones

Wednesday 10 March 2004 1:45:21 pm

Well, you could probably keep nesting those section blocks though that could get ugly real quick.There might be a better approach How many levels would be in this tree? Or, a different way to think of it, how many levels up would you want to check for content? How often do you think that you will need to grab content from a higher level?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

gareth eke

Friday 27 February 2009 2:15:17 pm

hi, this is exactly the functionality i need to implement, so i tried hacking Alex's code as below, but without success...did i miss something?

thanks, Gar

{section show=ne($node.object.data_map.name,' ')} {* check to see if the body is _not_ empty *}

{attribute_view_gui attribute=$node.object.data_map.name}

{section-else} {* body is empty so grab content from the parent *}

{let name=Child children=fetch('content','list',hash(parent_node_id,$node.parent_node_id,))}

{attribute_view_gui attribute=$node.object.data_map.name}

{/let}

{/section}