Forums / Developer / Tree View

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.

eZ debug

Timing: Jan 18 2025 04:05:51
Script start
Timing: Jan 18 2025 04:05:51
Module start 'content'
Timing: Jan 18 2025 04:05:52
Module end 'content'
Timing: Jan 18 2025 04:05:52
Script end

Main resources:

Total runtime1.4462 sec
Peak memory usage4,096.0000 KB
Database Queries204

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0076 588.6563180.8594
Module start 'content' 0.00771.3078 769.5156620.9219
Module end 'content' 1.31540.1307 1,390.4375337.3984
Script end 1.4462  1,727.8359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.2970210.0002
Check MTime0.00160.1092210.0001
Mysql Total
Database connection0.00120.085610.0012
Mysqli_queries1.365094.37992040.0067
Looping result0.00230.16232020.0000
Template Total1.411297.620.7056
Template load0.00210.146420.0011
Template processing1.409197.429720.7045
Template load and register function0.00020.016210.0002
states
state_id_array0.00150.103810.0015
state_identifier_array0.00090.062220.0004
Override
Cache load0.00190.1287540.0000
Sytem overhead
Fetch class attribute can translate value0.00190.132340.0005
Fetch class attribute name0.00090.065170.0001
XML
Image XML parsing0.00150.102340.0004
class_abstraction
Instantiating content class attribute0.00000.000770.0000
General
dbfile0.00230.1576340.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs