I know I've seen it somewhere before, but I don't know where.

How do I make the following link have a target=_blank attribute?

<?php
$link = array(
'#type'=>'link',
'#href'=>$url,
'#target'=>"_blank", // This is the only part that doesn't work
'#title'=>t("View on Google Maps"));
?>

Comments

judapriest’s picture

As you can see there : https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_pr...

'#target' don't exist, you are suppose to use '#options'

// create an array for readibilty
$options['attributes'] = array(
  'target' => '_blank', // simple example
);
 
// And renderable array for the link
$link = array(
  '#type' => 'link',
  '#href' => $url,
  '#options' => $options,
  '#title' => t("View on Google Maps"));