0

I have a few images in a node that can be opened in a fancybox lightbox. I would like to link those images together to create a gallery. To do so I need to add a rel attribute to my image link. How can I do this?

I tried editing the field.tpl.php template, but without any luck.

Help would really be appreciated.

7
  • You probably want hook_preprocess_link().
    – Alex Gill
    May 28 '13 at 14:07
  • Could you point me in the right direction how I do that?
    – driesp
    May 28 '13 at 14:08
  • Are you familiar with hooks?
    – Alex Gill
    May 28 '13 at 14:23
  • No I'm afraid not. I only have knowledge of html, css & js...
    – driesp
    May 28 '13 at 14:28
  • 1
    In your theme folder you have a file called 'template.php', here is where you implement 'hooks' on the theme layer to override core functionality. Have a look at origin-api.drupal.org/api/drupal/includes%21module.inc/group/… then have a look at this example drupalcode.org/project/icon.git/blob/… of how someone has used hook_preprocess_link in their module.
    – Alex Gill
    May 28 '13 at 14:36
1

I need to add a rel attribute to my image link. How can I do this?

You can add a data attribute to your link in l() function:

// your image
$image = array(
    'style_name' => 'the name of the image style',
    'path' => 'relative path to your image',
    'alt' => '',
    'title' => '',
    'attributes' => array('class' => array('some_class'))
);

// link elements
$text = theme('image_style', $image); // in your case it's an image
$path = 'link_url';
$options = array(
    'attributes' => array(
        'class' => array('some_link_class'), 
        'rel' => 'some_relation'
    ),
    'html' => true
);

$link =  l($text, $path, $options);

result:

<a class="some_link_class" rel="some_relation" href="/your_site/link_url">
    <img src="path to your image style" class="some_class" typeof="foaf:Image">
</a>

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.