0

I have a Drupal 7 site using the main menu for all pages. However, I've just added some unique landing pages for some advertising campaigns which all come from 'page--landing.tpl.php'

Oddly, my client wants just the 'page--landing.tpl.php' pages to have the main menu for these pages only work in such a way that the links all open in new windows (like target="_blank").

Does anyone know how to achieve this?

In the 'page--landing.tpl.php' file, the menu is created with:

<div id="menu">
<?php print $navigation; ?>
</div>

Thanks for any and all help given.

| improve this question | | | | |
1

There are many ways to do this

A quick way would be to use jQuery to rewrite the anchor tags in the menu with the target attribute

$( '.page--landing [menu link selector] ).attr( 'target','_blank' );

Using the Drupal API

function MODULE/THEMENAME_menu_link_alter(&$item)
{
   if (some logic that sets it only for the desired paths/context)
   {
     $item['options']['attributes']['target'] = '_blank';
   }
}

an example from the documentation for function hook_menu_link_alter

function MODULE/THEMENAME_menu_link_alter(&$item)
{
  if($item['link_path']=="admin/tutorial14333")
  {
  $item['options']['attributes']['target'] = '_blank';
  }
}
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.