Open Tree Menu in left of the page

Author Message

C G

Thursday 23 November 2006 4:19:45 am

Hi,

I'm new to ez publish and I want to change the menu behavior a little bit.

Now for example the left menu is something like this:

Categ_1
--------------------------
Categ_2
---------------------------
Categ_3

and when you click on "Categ_1" link will became:

Categ_1
______Categ_1_1
______Categ_1_2
______Categ_1_3
--------------------------
Categ_2
---------------------------
Categ_3

Now whatI I want to do is that when the menu is loaded into the page it should look like this:
Categ_1
______Categ_1_1
______Categ_1_2
______Categ_1_3
--------------------------
Categ_2
______ Categ_2_1
______Categ_2_2
______Categ_2_3
---------------------------
Categ_3
______Categ_3_1

This mean that each level/sub-lecel menu must be visible without clicking on parent level.

Thx.

Wise concepts for the right customer
http://www.blankconcept.com

Jacobo Quiles

Thursday 30 November 2006 3:11:21 am

Hi,

You could try something like this:

{def $second_level_children=array()}
{def $root_node_children=fetch('content', 'list', hash('parent_node_id', 2))} {* <-- node 2 is home, but can be any other node *}

{if gt($root_node_children|count,0)}
    <ul>
    {foreach $root_node_children as $child}
        <li>
            <a href={$child.url_alias|ezurl()}>{$child.name|wash()}</a>
            {set $second_level_children=fetch('content','list',hash('parent_node_id', $child.node_id))}
            {if gt($second_level_children|count,0)}
                <ul>
                {foreach $second_level_children as $child2}
                    <li><a href={$child2.url_alias|ezurl()}>{$child2.name|wash()}</a></li>
                {/foreach}
                </ul>
            {/if}
        <li>
    {/foreach}
    </ul>
{/if}

First fetch the elements of the top level, foreach element check if it has children, if so, show its children.

Cheers.

Microblau SL
http://www.microblau.net

C G

Sunday 03 December 2006 5:16:42 am

Hi Jacobo,

thx for your replay. I tested and work ok.

My problem is that I want to use flat_left.tpl layout and I don't know how to change it to work in the same way as your code.

My template code is below, maybe you can help me with it.

{let docs=treemenu( $module_result.path,
                    is_set( $module_result.node_id )|choose( 2, $module_result.node_id ),
                    ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
                    0, 5 )
                    depth=1
                    last_level=0}
        <ul>
        {section var=menu loop=$:docs last-value}
            {set last_level=$menu.last|is_array|choose( $menu.level, $menu.last.level )}
            {section show=and( $last_level|eq( $menu.level ), $menu.number|gt( 1 ) )}
                </li>
            {section-else}
            {section show=and( $last_level|gt( $menu.level ), $menu.number|gt( 1 ) )}
                </li>
                    {"</ul>
                </li>"|repeat(sub( $last_level, $menu.level ))}
            {/section}
            {/section}

            {section show=and( $last_level|lt( $menu.level ), $menu.number|gt( 1 ) )}
                {'<ul><li>'|repeat(sub($menu.level,$last_level,1))}
                <ul>
                    <li class="menu-level-{$menu.level}">
            
             {section-else}
                <li class="menu-level-{$menu.level}">
            {/section}

            <a {$menu.is_selected|choose( '', 'class="selected"' )} href={$menu.url_alias|ezurl}>{$menu.text|shorten( 25 )} </a>

            {set depth=$menu.level}
        {/section}
           </li>

        {section show=sub( $depth, 0 )|gt( 0 ) loop=sub( $depth, 0 )}
            </ul>
        </li>
        {/section}
        </ul>

{/let}

Wise concepts for the right customer
http://www.blankconcept.com

Jacobo Quiles

Monday 04 December 2006 12:48:48 am

Hi C G, just replace the code in your flat_left.tpl with my code, it should work fine.
The problem i think it comes from the treemenu function that is not fetching any node. Just replace all the code with mine and see if it works.

Microblau SL
http://www.microblau.net

C G

Monday 04 December 2006 12:59:10 am

Hi Jacobo,

Your code is working fine, I wrote that above. The probem with your code is regarding nodes priorities. In admin page a set some node priorities and I don't know how to use them in your code.

Any ideas?

Wise concepts for the right customer
http://www.blankconcept.com

Jacobo Quiles

Monday 04 December 2006 2:43:09 am

Hi, you mean set a sort by priority in admin interface and show the elements acording with the priority set?

Try this:

{def $second_level_children=array()
      $root_node=fetch('content','node',hash('node_id',2))
      $root_node_children=fetch('content', 'list', hash('parent_node_id', $root_node.node_id, 'sort_by', $root_node.sort_array))}

{if gt($root_node_children|count,0)}
   <ul>
   {foreach $root_node_children as $child}
       <li>
           <a href={$child.url_alias|ezurl()}>{$child.name|wash()}</a>
           {set $second_level_children=fetch('content','list',hash('parent_node_id', $child.node_id))}
           {if gt($second_level_children|count,0)}
               <ul>
               {foreach $second_level_children as $child2}
                   <li><a href={$child2.url_alias|ezurl()}>{$child2.name|wash()}</a></li>
               {/foreach}
               </ul>
           {/if}
       <li>
   {/foreach}
   </ul>
{/if}

Sorry if i missunderstand but my english is not very good.

Cheers.

Microblau SL
http://www.microblau.net

C G

Tuesday 05 December 2006 12:15:41 am

Hi Jacobo,
your code is working great.

Thx again.

Wise concepts for the right customer
http://www.blankconcept.com

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 30 2025 21:46:44
Script start
Timing: Jan 30 2025 21:46:44
Module start 'layout'
Timing: Jan 30 2025 21:46:44
Module start 'content'
Timing: Jan 30 2025 21:46:44
Module end 'content'
Timing: Jan 30 2025 21:46:44
Script end

Main resources:

Total runtime0.0221 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 588.1406151.2109
Module start 'layout' 0.00470.0039 739.3516220.7031
Module start 'content' 0.00860.0119 960.05471,009.9297
Module end 'content' 0.02050.0016 1,969.984441.9922
Script end 0.0221  2,011.9766 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002711.9802140.0002
Check MTime0.00115.1194140.0001
Mysql Total
Database connection0.00052.052710.0005
Mysqli_queries0.002410.733530.0008
Looping result0.00000.049610.0000
Template Total0.00114.810.0011
Template load0.00083.719710.0008
Template processing0.00021.052810.0002
Override
Cache load0.00052.477310.0005
General
dbfile0.00031.457980.0000
String conversion0.00000.039940.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