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?
Joe WeinpertSr Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Panagiotis Sweb developer - designer Commented:
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; ?>" ....
Steve BinkCommented:
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.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Joe WeinpertSr Software EngineerAuthor Commented:
panagiotiss -

I am assuming that your solution would be to create a custom module through the module manger for this?
Joe WeinpertSr Software EngineerAuthor Commented:
Steve Bink -

I will dig deeper into your solution.
Steve BinkCommented:
>>> 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.
Panagiotis Sweb developer - designer Commented:
yes you can put the link into a module
Joe WeinpertSr Software EngineerAuthor Commented:
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!
Steve BinkCommented:
Looking good.  Remember that your edited copy should exist in your template directory, e.g., as /templates/<template_name>/html/mod_menu/myAlternateLayout.php.  This keeps you from having to change core files, which means you'll be able to upgrade easily in the future without losing your changes.

Good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.