Hi.
How can I use an image as link using the l() function. I've noticed HTML tags for img (i.e. Only local images are allowed.) are filtered out.

TNX

Comments

awhite251’s picture

gollyg’s picture

there is an optional parameter you can pass to tell drupal you are passing html in the link. By default this is set to false.

l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
elvislam’s picture

I want to see the coding of this l function, can any one tell me?

Thanks

Elvis Lam

gollyg’s picture

all of the core api is at http://api.drupal.org

the link function (4.7) is at http://api.drupal.org/api/4.7/function/l

fatfish’s picture

l('<img src = "pic1.jpg" />', 'node/my_path', NULL , NULL,  NULL,  FALSE, TRUE);

..:| Tomer Fish |:..
fatFish - Lean Mean Coding Machine

techczech’s picture

This works perfectly. FYI: the function definition is on http://api.drupal.org/api/function/l/5.

______________________
Dominik Lukes
http://www.dominiklukes.net
http://www.hermeneuticheretic.net

nally’s picture

For Drupal 6, this became something like:

print l($text,'node/'.$node->nid, array('html'=>TRUE));

Christian Nally - B.C., Canada - http://sticksallison.com

kasalla’s picture

In D6 you can also do this:

Simple:

l('<img src="path/to/image.jpg"/>', $filepath, $options = array('html' => TRUE));

With ImageCache module:

l(theme('imagecache', $preset, $filepath, $alt, $title, $attributes = array()), $filepath,  $options = array('html' => TRUE));

With ImageCache module and Lightbox2 module:

l(theme('imagecache', $preset, $filepath, $alt, $title, $attributes = array()), $filepath, array('attributes' => array('rel' => 'lightbox[roadtrip]'), 'html' => TRUE));
#ImageCache provides a formatter function which does the same. To my mind this one here is more simple...

(formerly anstosser)
DOMAIN anstoss.de FOR SALE
Kasalla Media :: www.kasalla-media.de

WoRo’s picture

Can somebody tell me how to convert in function

l($text,'node/'.$node->nid, array('html'=>TRUE));

$node->nid to original picture location?

I use image module and there is something like:
l(image_display($image, IMAGE_THUMBNAIL), 'node/'. $image->nid, array('html'=>true));

and it produce link to a node - I wanna make link to original location of image on disk. Any idea?

Dp-Mtl’s picture

My snippet is like

    $src = drupal_get_path('module', yourmodule').'/images/icon.png';
    $img = theme_image($src);
    $path =  "yourpath"
    l($img,$path, array('attributes' => array('class' =>'link-image'),'html' => true,'query' => drupal_get_destination()));

Hope it helps you

ishmael-sanchez’s picture

Snippet from my template.php

 l(theme_image_style(array('path' => $variables['node']->field_logo['und']['0']['uri'], 'style_name' => '100x100')), 'node/' . $variables['node']->nid, array('html' => TRUE));