Forums / Setup & design / Direct Link to another Node in Menu

Direct Link to another Node in Menu

Author Message

Michael Fürst

Friday 25 April 2008 6:31:03 am

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

Maxime Thomas

Saturday 26 April 2008 1: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.

Maxime Thomas
[email protected] | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Michael Fürst

Monday 28 April 2008 5:41:40 am

Hi Thomas,

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

Ciao,
Mike

Michael Fürst

Wednesday 30 April 2008 4:32:41 am

Hi,

Ok, I've not the required know how at the moment to get the solution :)
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

Maxime Thomas

Wednesday 30 April 2008 1: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 !

Maxime Thomas
[email protected] | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Bruce Morrison

Wednesday 30 April 2008 2: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

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Michael Fürst

Friday 02 May 2008 2: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

Michael Fürst

Friday 02 May 2008 2: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

Michael Fürst

Friday 02 May 2008 3:06:03 am

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

Bruce Morrison

Friday 02 May 2008 6:28:44 pm

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

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Michael Fürst

Saturday 03 May 2008 1:52:08 am

Hi Bruce,

"_blank" or "_self" attribute checkbox is a good idea ;)
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

Michael Fürst

Saturday 03 May 2008 12: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

André R.

Monday 29 December 2008 9:14:51 am

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.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom