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}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:34:43
Script start
Timing: Jan 18 2025 11:34:43
Module start 'layout'
Timing: Jan 18 2025 11:34:43
Module start 'content'
Timing: Jan 18 2025 11:34:44
Module end 'content'
Timing: Jan 18 2025 11:34:44
Script end

Main resources:

Total runtime0.9375 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.0469152.6406
Module start 'layout' 0.00580.0024 740.687539.4922
Module start 'content' 0.00820.9277 780.1797591.4531
Module end 'content' 0.93590.0015 1,371.632816.1250
Script end 0.9374  1,387.7578 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.3768160.0002
Check MTime0.00140.1513160.0001
Mysql Total
Database connection0.00090.094010.0009
Mysqli_queries0.878193.6623650.0135
Looping result0.00070.0713630.0000
Template Total0.907796.820.4539
Template load0.00230.243420.0011
Template processing0.905496.579920.4527
Template load and register function0.00020.023610.0002
states
state_id_array0.00100.108810.0010
state_identifier_array0.00080.082720.0004
Override
Cache load0.00190.2080310.0001
Sytem overhead
Fetch class attribute can translate value0.00090.099630.0003
Fetch class attribute name0.00120.130560.0002
XML
Image XML parsing0.00090.095230.0003
class_abstraction
Instantiating content class attribute0.00000.001870.0000
General
dbfile0.00070.0752160.0000
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 20
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs