Adding a custom menu link with parameters to open in a new window

Adding a custom menu link with parameters to open in a new window

by Chardelle Busch -
Number of replies: 0
Picture of Core developers

Please NOTE this is for Moodle 2.4.4

The custom menu settings do not allow for opening a link with parameters in a new window.  I need to add a link to an external support ticket system and it MUST open in a new window.  So, in order to do this, I have been creating a custom menu function (see the FAQ on adding My Courses to custom menu for instructions), and adding the links (this is a dropwdown) like this:

  $supportmenu = $menu->add('Tech Support', new moodle_url('#'), 'Tech Support');
$supportmenu->add("<a class=\"yui3-menuitem-content\" href=\"https://example.com/livehelp.php?page=leavemessage&amp;department=11&amp;tab=2\" onclick=\"this.target='_blank';\">Email Tech Support</a>");    

However, I have now moved to the new bootstrap theme and this doesn't work there.  For some reason, bootstrap REQUIRES a new moodle_url and if it isn't there it adds <a href = "# "></a> as an extra line above the link-which is not ideal.  

The only way I have found to get around this is to hardcode the menu into its own file and then include that instead of the custom menu in my layout page.  So for example the code above in my menu.php file looks like:

<ul class="nav">
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Tech Support<b class="caret"></b></a>

<ul class="dropdown-menu">
<li><a href="https://example.com/livehelp.php?page=leavemessage&amp;department=11&amp;tab=2" onclick="this.target='_blank';">Email Tech Support</a>
</ul>
</ul>

This seems to work fine.  If anyone has any better ideas or comments, please let me know.

 


Average of ratings: -