Link to home
Start Free TrialLog in
Avatar of Joe Weinpert
Joe Weinpert

asked on

Appending user name to menu external URL link. Joomla! 3.4.3

We added a menu item to our new Joomla intranet page. it is simply an application's url link set in the Menu Manager: Edit Menu Item page like this:

Menu Item Type = External URL
Link = http: //server/pio/pio.html
Target Window = New Without Navigation


It works fine. The application fires as it is supposed to. What we would like to do at this point is append the Joomla user's login name to the link so that it automatically logs them in to the app instead of prompting for a user ID again. This is what the URL link would need to look like if I were to click on the menu item to run the external app without being prompted for a user ID:

http: //server/pio/pio.html]?userID=jweinpert

So how can we append the Joomla's user login ID to the Menu Type Item External Link whenever a user clicks on it?
Avatar of Panagiotis S
Panagiotis S
Flag of Greece image

One easy way is not to use a menu item but just a link in which you will provide the user name and the pass.

if a user is logged in you can easily can get his credentials so the link will be something
http: //server/pio/pio.html]?userID="<?php echo &usename; ?>" ....
Menu items are printed through mod_menu, with the view being selected according to the type of menu item.  The default view, which is applied to external URLs, is found in /modules/mod_menu/tmpl/default_url.php.  If you create an override for this file, you can check for a logged in user and append the username as the item is being printed.

Instead of a template override, you may want to consider a chrome style, or an alternate view.  These will let you target the menu item individually instead of having all your menu items go through the new view.
Avatar of Joe Weinpert
Joe Weinpert

ASKER

panagiotiss -

I am assuming that your solution would be to create a custom module through the module manger for this?
Steve Bink -

I will dig deeper into your solution.
>>> create a custom module through the module manger for this

While a custom module work also work, I think it is a bit of overkill for this problem.  All you need is a small adjustment to how an item is rendered.  That item already exists in Joomla, and Joomla provides overrides as a method of accomplishing this very task.
yes you can put the link into a module
Steve Bink

I am using Joomla! 3.4.3.  The link you posted that am looking at is for Joomla! 2.5

so ...

I made a backup copy of the original /modules/mod_menu/tmpl/default_url.php and inserted two lines into the original:

$flink = $item->flink;

// Added user to menu link ------------
$user   = JFactory::getUser();
$flink .= "?userID=" . $user->username;
// ------------------------------------

$flink = JFilterOutput::ampReplace(htmlspecialchars($flink));

Open in new window


This works fine.

Thank you for pointing where to go!
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial