eZ Community » Forums » Setup & design » Direct Link to another Node in Menu
expandshrink

Direct Link to another Node in Menu

Direct Link to another Node in Menu

Friday 25 April 2008 3:31:03 pm - 12 replies

Hi there,

I'd like to build a shortcut in a menu with a node.
Following Site Structure:

root (Frontpage)
|-------- Tennis (Frontpage)
| --------- News (??)
| --------- Calendar (event_calendar)

|-------- Badminton
| ---------- Results (Article)

My problem is:
If a user clicks on "Tennis" in den Menu, he sees the Tennis Frontpage. The Content on this node is placed via Blocks (ezFlow). Below the Node "Tennis" there is another Node called "News" wich is a sub-menu item of tennis.

And now, if the user clicks on "News", he should be redirected to the "Tennis" Node. Has anyone an idea how to do this? I'm looking for an "internal shortcut" node, but i didn't find one till now...

Would be great if someone can help me with this problem,
Tanks & Ciao,
Mike

Saturday 26 April 2008 10:01:23 am

You have two easy solutions :
- you can create a content of Link type and call it News. The URL you would provide will be the Tennis URL.
- you can create a class called "Relation link" which will contain only a name and a relaion object. You create then a "Relation link" called News pointing on Tennis. You will have to do some template, but it's cleaner.

Monday 28 April 2008 2:41:40 pm

Hi Thomas,

Thanks, the second solution sounds great.
I'll try to find the code required blunk.gif Emoticon (redirection on node-type would be my idea?)

Ciao,
Mike

Wednesday 30 April 2008 1:32:41 pm

Hi,

Ok, I've not the required know how at the moment to get the solution happy.gif Emoticon
I've created a class "internal_shortcut":

Class: internal_shortcut
Attributes:
         - name [TEXT]
         - Object Relation [Object]

So if i'd like to create a menu shortcut, i'll just create an object instance of this class and link to the node object wich the user should be redirected to.

<b>My problem:</b>
Now I have no idea how to create the required functionality if a user clicks on one of this shortcuts? In the system there should be a PHP function like "header: location..." wich is assigned to objects of the type "internal shortcut".

I first tried to use template overrides, but thats logically the completely wrong way (the redirection should be done before any template is parsed).

So does anyone know, how to "inject" specific code for a class / object? Do i have to create an own extension for this requirements?!?

Hope anyone can give me a hint,
thanks a lot,
Mike

Wednesday 30 April 2008 10:48:12 pm

I guess there is a misunderstanding, when I was talking about class, I was talking about content class, not PHP class.

You can create a content class using the administration interface : Setup > Classes > New class

Then you must choose the correct datatypes which will compose your class :
- Name, a Line of text attribute
- Object (or whatever), a relation object attribute

Finally, you will just have to write a template for this content type override the default one (node/view/full.tpl).

There's a lot of information in the documentation, I suggest you to read it very carefully and specially this part :
http://ez.no/doc/ez_publish/technical_manual/4_0/concepts_and_basics

Sometimes eZ is not easy... Don't give up the fight !

Wednesday 30 April 2008 11:33:04 pm

Hi Mike

I use a technique similar to that described by Maxime, where there is a specific content class (mine is called a Menu Llink) that contains the link & label information.

The second step is overriding the menu generating templates to check for this content type and use the "link" attribute for the href instead of the url_alias. This way the generated link points to the required location and not the node itself.

Cheers
Bruce

Friday 02 May 2008 11:40:47 am

Hi Guys!

No, i also talked about content classes.
But i had a completely other idea of how to redirect the user.

In my concept, the Link is called "/site/tennis/news". After the user clicks on this link he will be redirect during page load via a PHP Method to "/site/tennis" (for example with a "header" function).

The much easier way (wich i didn't see before) is to simply create the "/site/tennis" link via the linked object attributes.

Man, thanks a lot for this simple but useful hint ;o) I was on the wrong way...

Ciao,
MIke

Friday 02 May 2008 11:44:33 am

Just another simple question:
How am i able to define the "default" template for objects of a content class? (for example objects of class type "internal link)?

In my override declaration I'm only able to define the override template an tell the system, what's the original template. But where is it defined!?

Thanks & bye,
Mike

Friday 02 May 2008 12:06:03 pm

Hi Bruce!

Is your "link" attribute in the class a simple text field where you enter the URL directly, or do you use a "object relation" datatype? (thats the way i'd like to build the class).

Ciao,
Mike

Saturday 03 May 2008 3:28:44 am

Hi Mike

The content class I use consists of a url and ccheck box attribute. The url contains the link & title, the checkbox is to allow for the link to be opened in another window. I typically use these to splice custom module content into the main node tree.

To do what you have described you can simply use a related object datatype. This way if the URl/name of the object changes the menu will be updated accordingly.

With this said I would look into the IA of your site. I've always found that if node tree doesn't reflect the site/nav structure then problems tend to crop up.

cheers
Bruce

Saturday 03 May 2008 10:52:08 am

Hi Bruce,

"_blank" or "_self" attribute checkbox is a good idea blunk.gif Emoticon
I now built the class with an object relation. I've only one last problem: I can't find the url_alias (or path) of the related object..!?

My Object path:
$menuSubTopItemsMenu.object.data_map.link_to_object

"link_to_object" is my link attribute. Do you possible know where to find the path of this linked object? I already nearly tried every attribute but i can't find it... Is there a function (for example "getPath(ObjectId)"..

Thanks & ciao,
Mike

Saturday 03 May 2008 9:49:47 pm

Ok, after diggin' around some hours in the attributes an sub-objects i found the right way. Here's the code for building an internal shortcut link with an own class-type (identifier: internal_shortcu):

{foreach $menuSubTopItems as $menuSubTopItemsIndex => $menuSubTopItemsMenu}
			<li>
				{* ************************************************** *}
				{* Check if this is a internal or a standard link *}
				{* ************************************************** *}
				{if eq($menuSubTopItemsMenu.object.content_class.identifier,'internal_shortcut')}
					<a href={$menuSubTopItemsMenu.object.data_map.link_to_object.content.main_node.url_alias|ezurl()}>{$menuSubTopItemsMenu.name|wash}</a>
				{else}
					<a href={$menuSubTopItemsMenu.url_alias|ezurl()}>{$menuSubTopItemsMenu.name|wash}</a>
				{/if}
			</li>
		{/foreach}

Hope this maybe will help someone else...

Ciao,
Mike

Monday 29 December 2008 6:14:51 pm

The eq($menuSubTopItemsMenu.object.content_class.identifier,'internal_shortcut') code should be rewritten to eq($menuSubTopItemsMenu.class_identifier,'internal_shortcut') to avoid fetching the class for each menu entry.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from