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}

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 18:21:12
Script start
Timing: Jan 18 2025 18:21:12
Module start 'layout'
Timing: Jan 18 2025 18:21:12
Module start 'content'
Timing: Jan 18 2025 18:21:13
Module end 'content'
Timing: Jan 18 2025 18:21:13
Script end

Main resources:

Total runtime0.6753 sec
Peak memory usage4,096.0000 KB
Database Queries67

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 587.9063152.6250
Module start 'layout' 0.00600.0029 740.531339.4297
Module start 'content' 0.00890.6651 779.9609656.4141
Module end 'content' 0.67390.0013 1,436.375020.1875
Script end 0.6753  1,456.5625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4670160.0002
Check MTime0.00140.2019160.0001
Mysql Total
Database connection0.00080.113110.0008
Mysqli_queries0.601289.0323670.0090
Looping result0.00060.0897650.0000
Template Total0.651696.520.3258
Template load0.00170.256620.0009
Template processing0.649996.232420.3249
Template load and register function0.00030.038410.0003
states
state_id_array0.00030.044710.0003
state_identifier_array0.00060.091520.0003
Override
Cache load0.00150.2258580.0000
Sytem overhead
Fetch class attribute can translate value0.00120.180540.0003
Fetch class attribute name0.00120.183270.0002
XML
Image XML parsing0.00590.869440.0015
class_abstraction
Instantiating content class attribute0.00000.005880.0000
General
dbfile0.00520.7732220.0002
String conversion0.00000.001640.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs