1

In views,for image field, I have selected "output this field as link" and in link path, I wrote "node/[nid]". Link works and open in same window. How to open the link in a new window? I dont see any option in view.

Thanks

3

1) Click your image field at your views 2) Click Rewrite results. Check Output this field as a link. Key in your URL in the Link Path

enter image description here

) 3) At Target text field, key in this "_blank"

enter image description here

|improve this answer|||||
  • I glad it help. Do you mind give me vote up? Lol – peifa Apr 14 '15 at 2:40
  • 1
    I have the same problem but this solution does not work!! is there any other way? – shekoufeh Apr 21 '15 at 4:15
  • May I know what you key in the link path and what is the option you choose for formatter? – peifa Apr 21 '15 at 4:32
  • my link path is the token of image field and formatter is just image – shekoufeh Apr 21 '15 at 6:28
1

To do so programmatically, you need to define ThemeName_preprocess_views_view_fields function. Then in this function you should theme the views output. If the image field name is field_image then write:

function ThemeName_preprocess_views_view_fields(&$variables)
{
      $view = $variables['view'];
      if($view->name == "TheViewName")
      {
           $variables['image'] = $variables['fields']['field_image']->FIND THE IMAGE PATH BY DEVEL MODULE;
           $variables['link'] =  $variables['fields']['field_image']->FIND THE IMAGE LINK ADDRESS BY DEVEL MODULE;  
      }
}

Then create views-view-fields--TheViewName--DisplayNameOfView.tpl file and in this file write

$image = strip_tags($image) ;
<a href="<?php print $link?>" target="_blank"><img src="<?php print $image;?>"</a>

Notice that you should install devel module to get required information about the image, its link and etc.

Clearly in this method you will have more choices of displaying the link and you can also use this method to open the image in a popup window.

This is the main idea of doing this and I always use this. I didn't test this code but a few modification might be needed. for example in views-view-fields--TheViewName--DisplayNameOfView.tpl you can use <?php print $fields['field_image']->content; ?> to output the entire linked image.

|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.