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}

eZ debug

Timing: Jan 18 2025 15:19:12
Script start
Timing: Jan 18 2025 15:19:12
Module start 'content'
Timing: Jan 18 2025 15:19:13
Module end 'content'
Timing: Jan 18 2025 15:19:13
Script end

Main resources:

Total runtime1.4403 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.0090 587.6875180.8438
Module start 'content' 0.00901.2686 768.5313661.4922
Module end 'content' 1.27760.1626 1,430.0234341.0859
Script end 1.4402  1,771.1094 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.2780210.0002
Check MTime0.00150.1052210.0001
Mysql Total
Database connection0.00110.076310.0011
Mysqli_queries1.367994.97562040.0067
Looping result0.00190.13062020.0000
Template Total1.400097.220.7000
Template load0.00220.154220.0011
Template processing1.397897.046920.6989
Template load and register function0.00010.008310.0001
states
state_id_array0.00130.091510.0013
state_identifier_array0.00210.145220.0010
Override
Cache load0.00190.1353580.0000
Sytem overhead
Fetch class attribute can translate value0.00080.059050.0002
Fetch class attribute name0.00090.063570.0001
XML
Image XML parsing0.00250.175550.0005
class_abstraction
Instantiating content class attribute0.00000.000880.0000
General
dbfile0.00310.2129330.0001
String conversion0.00000.000430.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
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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs