Forums / Developer / External links in menu

External links in menu

Author Message

Valentin Svelland

Wednesday 16 July 2003 12:15:08 am

My leftmenu is generated by traversing folders and their childs (see code under). But sometimes I need to include a external link to some other site or perhaps another node outside the parent folder of my site. What's the best way to handle this?

I've noticed the object "link". Is it possible to include link-object to be shown in my menu-code under:

<!-- my leftmenu -->

{* Set your top category here *}
{let top_cat=102
used_node=false()}

{* See if we have already a node id otherwise use the top category as current node *}
{section show=is_set($DesignKeys:used.node)}
{set used_node=$DesignKeys:used.node}
{section-else}
{set used_node=$top_cat}
{/section}

{* Get a proper node object *}
{let node_obj=fetch(content,node,hash(node_id,$used_node))}

{* FIRST LEVEL *}
{section loop=fetch(content,list,hash(parent_node_id,$top_cat, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))}
<img src={"spacer_grey.gif"|ezimage} width="100" height="1" /><br />
<img src={"spacer.gif"|ezimage} width="100" height="2" /><br />
<b><a class="menulevel1" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br /></b>

{* SECOND LEVEL *}
{section show=$node_obj.path_array|contains($:item.node_id) loop=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))}
<a class="menulevel2" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br />

{* THIRD LEVEL *}
{section show=$node_obj.path_array|contains($:item.node_id) loop=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))}
<a class="menulevel3" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br />

{* FOURTH LEVEL *}
{section show=$node_obj.path_array|contains($:item.node_id) loop=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))}
<a class="menulevel4" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br />
{/section}
{/section}
{/section}
<img src={"spacer.gif"|ezimage} width="100" height="3" /><br />
{/section}
{/let}
{/let}

Valentin Svelland

Friday 25 July 2003 12:56:43 am

Still haven't figured this one out.. :(

Alex Jones

Friday 25 July 2003 6:43:26 am

Valentin, I'm running into the same issue myself. I tried using a "link" but I cannot find a way to have it poitn directly at the URL in my navigation. Instead, it always links to the page (node) about the external site.

It doesn't make much sense.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Petrus Viitanen

Monday 25 April 2005 4:44:43 am

Hi both of you,

I'm struggling with the same problem here, so if you have found a solution please share it with us. I would like to create links that open directly from the menu.

-Peetuli

Yngve Bergheim

Tuesday 03 January 2006 2:29:14 am

I also needed external links in the left menu. So I wrote an modification of templates/menu/flat_left.tpl

Now you just can include an external link with the build in eZ link class. Never figured out what the link class was good for anyway when you have other ways to include links in articles.

Make sure you have included link class in menu.ini.append.php [MenuContentSettings].

If you want you can hide link class in folder.tpl.

The complete file templates/menu/flat_left.tpl:

{def $menu_level_one_less=0}
{def $hideSubMenu=false()}
{* We can't manipulate $menu.url_alias, so we make an local variable *}
{def $this_url_alias=''}

{let docs=treemenu( $module_result.path,
                    is_set( $module_result.node_id )|choose( 2, $module_result.node_id ),
                    ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
                    0, 10 )
                    depth=1
                    last_level=1}
                    
	<h3 class="hide">{"Left menu"|i18n("design/base")}</h3>  
	<ul>

	{section var=menu loop=$:docs last-value}

		{set last_level=$menu.last|is_array|choose( $menu.level, $menu.last.level )}

		{* Bug fix: folder as sub items beneath an article make the menu break *} 
		{* This fix make all menu items that have an illegal menu.level jump (more than 1) *}
		{* not to be displayed *}
        {set $menu_level_one_less=sub( $menu.level, 1)}
        {if gt( $menu_level_one_less, $last_level ) }
        	{set $hideSubMenu=true()}
        {/if}
        {if eq($hideSubMenu, true() )}
        	{if eq($menu.level, 0)}
        		{set $hideSubMenu=false()}
        	{/if}
        {/if}
		
        {* Display external urls in a link class *}
        {* NB. Make sure you have included link class in: *} 
        {* menu.ini.append.php [MenuContentSettings] *}
        {def $my_node=fetch( 'content', 'node', hash( 'node_id', $menu.id ) )}        
		{set $this_url_alias=$menu.url_alias}
		{if ne($my_node.object.data_map.location.content, '')}
			{set $this_url_alias = $my_node.object.data_map.location.content}
		{/if}  	
        
        {* Don't show some menu nodes *}
        {if and( eq($hideSubMenu, false() ), ne($menu.id, 1267), ne($menu.id, 1330) )}
     	  	{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 {$menu.is_selected|choose( '', 'class="on"' )}>
	        {section-else}
	            <li {$menu.is_selected|choose( '', 'class="on"' )}>
	        {/section}
	
	        <a {$menu.is_selected|choose( '', 'class="on"' )} href={$this_url_alias|ezurl}>{$menu.text}</a>
			
	        {/if}
	        {set depth=$menu.level}
	    {/section}
	       </li>
	
	    {section show=sub( $depth, 0 )|gt( 0 ) loop=sub( $depth, 0 )}
	        </ul>
	    </li>
		{/section}
   
    </ul>

{/let}
{undef $this_url_alias}
{undef $menu_level_one_less}
{undef $hideSubMenu}