Closed (fixed)
Project:
Drupal core
Version:
7.0
Component:
image system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
17 Mar 2011 at 15:56 UTC
Updated:
12 Oct 2011 at 21:16 UTC
I knew how to do that in D6, using an overide of an imagecache function.
But now, in D7, I just use the core image field (such as we have in Article content type).
In my template.php, I added
function bartik_image($variables) {
$variables['attributes']['target'] = "_blank";
$attributes = $variables['attributes'];
$attributes['src'] = file_create_url($variables['path']);
foreach (array('width', 'height', 'alt', 'title', 'target') as $key) {
if (isset($variables[$key])) {
$attributes[$key] = $variables[$key];
}
}
return '<img' . drupal_attributes($attributes) . ' />';
}
I get the new attribute, but it does not change the link.
How to proceed?
Comments
Comment #1
bfroehle commentedThe actual linking is done with the A tag surrounding the image.
The theme function which produces the image and link is
theme_image_formatter().
Could you accomplish this with a preprocessor function? Something like
Comment #2
sahuni commentedIt's exactly that, thanks a lot!
Comment #3
bfroehle commentedGlad to hear it. :)
Comment #5
Peasoup commentedHey :)
Sorry to reopen a closed issue, but this is exactly what i also want to do, but apparently I do something wrong. I added bfroehle's code (except the php tags of course) at the end of my template.php, but nothing changed. What am I doing wrong?
(I'm using a "subtheme" of bartik, basically just a clone in sites/all/themes, with minor changes, which do apply)
Thanks!
Comment #6
Jarvis Lukow commentedHey there,
I was looking for something similar before, but didn't want to add the '_blank' target to all "a" tags, so I added the following code in my module. Hope this helps someone else.
Thanks,
Comment #7
jond commentedjarvislukow, did you add this as a custom module, or in the template.php file?