Views Module: Target von Links

Views Module: Target von Links

Bei einem aktuellen Projekt wollte ich einen View mit verlinkten Bildern erstellen - soweit stellt dies auch kein Problem dar - man kann den Output eines Link-Feldes ja auf das Bild "umleiten" (Output this field as a link).

Leider besteht dann noch das Problem, dass der Link im selben Fenster geöffnet wird. Macht sich bspw. bei verlinkten Partnerseiten o.ä. Sachen nicht so gut.. Über den Hook TEMPLATENAME_preprocess_block lässt sich dies aber ändern..

function TEMPLATENAME_preprocess_block(&$vars) {
  // Check that we're looking at the right block.
  if ($vars['block']->delta == 'BLOCKDELTA') {
    // Use a regular expression to append a target attribute to each anchor tag.
    $vars['block']->content = preg_replace('/<a (.+?)>/','<a $1 target="_blank">',$vars['block']->content);
  }
}