Hi,
I am busy rewriting a module for drupal 5. When I first wrote the module I hard coded the <a href> elements with the image inside them, as I could not pass <img> elements to l().

I have read up on the forums and some people suggest using css but this seems more suited to menus than the gallery I am working with.

What I am trying to do is something like this l("<img src="$imgurl">","node/view/$node->nid") all this does is give me a link with the text and not the image.

Regards
Laurence

Cape Town, South Africa

Comments

heine’s picture

From http://api.drupal.org/api/5/function/l :

  l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
$html Whether the title is HTML, or just plain-text. For example for making an image a link, this must be set to TRUE, or else you will see the encoded HTML.

If you set the last argument to TRUE, your link text will not be escaped and the image should show up.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

baldy’s picture

Hi,
Thanks thats exactly what I needed. Here is my final code :

$image_tag = theme_image("$img_path");
$node->body .= l($image_tag,"pblog/$node->nid$med_image",NULL,NULL,NULL,NULL,TRUE);

Regards
Laurence

tassoman’s picture

Would be more useful moving the argument $html bool just after url argument, to avoid needing of inserting of null arguments?

___________
by Tassoman

geek, net addicted user

TapocoL’s picture

Just to note, all themes should be ran through this function:

theme('image', $img_path);

This allows any customizations in your template theme file to make their changes accordingly.

-Craig Jackson
-Web Developer

tkachuk.i.m’s picture

You've helped me to solve that problem ))) thanks!

JonGirard-1’s picture

I'm having a very simillar problem trying to change a text "delete" link being printed with views into an image. I've located the code responsible for the output of the link-

if (node_access('delete', $data)) {
    $link_text = $fielddata['options'] ? $fielddata['options'] : t('Delete');
    return l($link_text, "node/$data->nid/delete", NULL, drupal_get_destination());
  }

and I changed it to:

if (node_access('delete', $data)) {
  	$img_path = ("/sites/all/themes/BDC/success.png");
    $link_text = theme_image("$img_path");
    return l($link_text, "node/$data->nid/delete", array(), drupal_get_destination(), NULL, NULL, FALSE, TRUE);
  }

Still nothing. I've also tried a number of other code fixes, all with the same result. Nothing being outputted at all.

What am I doing wrong?

Jon.

eaochoac’s picture

For Drupal 6, this became something like:

print l('<img src=\"imagepath\">','node/'.$node->nid, array('html'=>TRUE));
lellobot’s picture

The 'array('html'=>TRUE)' part of this worked for me! So my code, with an ubercart thumbnail, looks like:

$img = theme('imagecache', 'uc_thumbnail', $node->field_image_cache[0]['filepath']);
$output .= '<p style="text-align:center;">' . l($img, "node/$node->nid", array(html=>TRUE)) . '</p>'; 

Thanks so much!

begun’s picture

I also had similar problem and solved it using the CSS approach, which is achieved by adding a background image and then offsetting the text so that it is not visible (http://xavisys.com/css-trick-turning-a-background-image-into-a-clickable...).

I know this isn't the coding approach you were looking for, but it works and is very easy to implemented.