Tree View

Author Message

Håkan Bergman

Thursday 14 October 2010 7:09:24 am

Hello,

I have been trying to display a tree view.
This is a sample that I have for now:

Object A
-> Child A
-> Grandchild A
-> Child B
-> Grandchild B
Object B
-> Child C
-> Grandchild C
-> Grandchild D
The tree view is listing them in this order:
* Object A
* Object B
* Childobjects
* Grandchildobjects
I need it to iterate Object A + child(s) then Object B + child(s) and so on.
I tried to search the forum and someone else had the same issue but never got a perfect answer on how to solve it practically. Should I use another method or can I add something to the fetch method that will list the objects the way I want?

At the moment the code looks like this:
{def $tree = fetch ( 'content', 'tree', hash( 'parent_node_id', $id, 'class_filter_type', 'include', 'class_filter_array', array ('class') ) ) }

Best regards,

Håkan

Thiago Campos Viana

Thursday 14 October 2010 10:06:37 am

The problem is that a tree is not a tree but a list, see the comments on tree fetch function documentation

You need to specify a depth of 1 and parse the children of each node:

{def $tree_node = fetch('content', 'tree', hash( 'parent_node_id', $pagedata.root_node, 'depth', 1 ) ) }
<ul>
{foreach $tree_node as $key => $item}
        <li{cond($key|eq(0), ' class="firstli"')}><a href={$item.url_alias|ezurl(no)}>{$item.name}</a>
            <ul>
    {foreach $item.children as $subkey => $subitem}
            <li{cond($subkey|eq(0), ' class="firstli"')}><a href={$subitem.url_alias|ezurl(no)}>{$subitem.name}</a></li>
    {/foreach}
            </ul>
        </li>
{/foreach}
</ul>

eZ Publish Certified Developer: http://auth.ez.no/certification/verify/376924

Twitter: http://twitter.com/tcv_br

André R.

Friday 15 October 2010 12:42:32 am

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Miscellaneous/content_structure_tree/

It's seriously difficult to work with, and undocumented, but it does fetch content in a tree and maintain structure.

See use in webin ( from "contentstructure" and bellow ):
ezwebin/design/ezwebin/templates/menu/flat_left.tpl

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Håkan Bergman

Friday 15 October 2010 12:43:15 am

Thanks.

I took your example and implemented it in my template and it works to depth 2.

What I wanted to avoid was to create manual loops. Right now the code manually loops through depth 2 and prints it.

But if I want to show depth 3 inside of depth 2 I need to do another foreach, and for depth 3 inside of depth 2 I need to add another one.

This probably works if you know you have same depths to show in every case.

But in this case the depth can be dynamic and infinite, so it have to automcatically loop 1 or 50 depths.

Is there a way to do that without adding a new foreach and instead letting the template code automatically print all the child nodes in the right order?

Best regards,

Håkan

Håkan Bergman

Friday 15 October 2010 12:46:12 am

Thanks André.

Will take a look at that.

Im trying to learn so undocumented functions aint the best for me at the moment, but I will give it a shot and try it out.

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 05:11:25
Script start
Timing: Jan 18 2025 05:11:25
Module start 'layout'
Timing: Jan 18 2025 05:11:25
Module start 'content'
Timing: Jan 18 2025 05:11:25
Module end 'content'
Timing: Jan 18 2025 05:11:25
Script end

Main resources:

Total runtime0.0183 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 589.0625152.6094
Module start 'layout' 0.00700.0037 741.671939.4063
Module start 'content' 0.01070.0057 781.078193.5234
Module end 'content' 0.01640.0019 874.601638.2891
Script end 0.0183  912.8906 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003016.4077140.0002
Check MTime0.00137.2273140.0001
Mysql Total
Database connection0.00126.484210.0012
Mysqli_queries0.003016.570430.0010
Looping result0.00000.147010.0000
Template Total0.00158.210.0015
Template load0.00084.490710.0008
Template processing0.00073.689110.0007
Override
Cache load0.00063.181610.0006
General
dbfile0.00031.535580.0000
String conversion0.00000.054740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs