Hi,

I'm interesting to use link to create an image link where only the link can be changes and the images is set. I though doing it thru the themplate file, like this:

Only local images are allowed.

Instead on thr a href printing the field. My question is: is there a way to print the field and insert the image in it?

Thanks in advance

Comments

Sooki’s picture

When I wrote like this, I meant this:

<a href="">
<img csr=""/>
</a>
quicksketch’s picture

I'd suggest you create a custom module that implements hook_field_formatter_info() and creates a new formatter for your site that is "link with image". If that sounds too daunting, then you could simply override the default formatter. Open link.module, copy the "theme_link_formatter_default" function, paste it into your template.php, rename the function to "[name of your theme]_link_formatter_default", then change as necessary to put whatever image you like in there.

Sooki’s picture

Status: Active » Fixed

The solution turned out to be so simple, after viewing the way the module output the link, I was like "Hey, what if I just put the html code in the title field?" and it worked!

samirnassar’s picture

Doesn't this leave link open to malicious entering of markup if any random markup can be put in the title field?

quicksketch’s picture

No, link.module uses a strict list of acceptable inline elements that are allowed in link titles. Also, note that HTML is only allowed if you're using a predefined title for all links (so it's setup by the administrator) or if you allow tokens to used by your end-users. Either way, it's still run through filter_xss() and doesn't allow scripts or css. See #214194: Allow HTML in Title (using tokens).

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

sittard’s picture

What would be required to get the output like this:

<a href="">
<span>link title</span>
</a>
Ela’s picture

#3, Sooki, Thank you for that great tip!! :D