I've got a view and one of the fields is displayed as a link. (Output this field as a link
is cheked). But now i want those links to have target=_blank
attribute.
How can i achieve this?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI've got a view and one of the fields is displayed as a link. (Output this field as a link
is cheked). But now i want those links to have target=_blank
attribute.
How can i achieve this?
When you check Output this field as a link
there is a Target
input box available (Further down). In that input box you can write _blank
. (D7)
edit: I just saw the answer whitefleaCH gave you - I never use the output settings as i prefer to style my views using templates to clean up the code - so i didn't know that option existed, though I presumed it did..
You can either use the themeing part of view and create your own template for the row style and simply hardcode the link attribute into it there (click the 'theme: information' part in the advanced settings of your view to see how to name your theme template).
Or which is probably easier - depending on how much themeing you'll be doing to your view - is to use jquery by doing the following:
Create a .js file and paste the following in into it (create a new textfile and save as yourfile.js):
(function($) {
$(document).ready(function() {
$('.CLASS a[href]').attr({
target: "_blank",
title: "Opens in a new window"
})
});
}(jQuery));
Change the CLASS bit with the class surrounding your link and save the file.
Upload your YOURFILE.js to your theme directory (eg: sites/all/themes/YOURTHEME/) Open YOURTHEME/template.php file and tell it to load your .js file by adding the following line
drupal_add_js(drupal_get_path('theme', 'YOURTHEME').'/assets/js/YOURFILE.js');
Clear your cache and all links surrounded by
<div class="CLASS"><a href="">Link</a></div>
will automatically open in a new window.
Of course you can do a lot more with the above script, like add a special class to the links so you can use .css to style them differently, or append some symbol or image etc etc ...
I hope this helps.
Linked Field module with Tokens.
Just brilliant!
After that in your View you may select Show:Content | Teaser (Teaser or any other preferable display)
The same but kinda verbose way give us the Image Link Formatter module, but only for images.
@whitefleaCH gives good solution too! (only for Views module)