Forums / Developer / Open Tree Menu in left of the page

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