I'm mucking around with a phptemplate theme, and I want to build a link myself. The link is going to be text, and I want to add the "onmouseover" and "onmouseout" commands into it. Wanting to do things the right way, I'm trying to use the "l" (pronounced "el") function to do this. Here is the code:

    $title_attribs['onMouseover'] = '"ddrivetip(\'fixedtipdiv-' . $node->nid . '\', \'400\')';
    $title_attribs['onMouseout'] = '"hideddrivetip()"';
    $cell['data'] = l($node->node_title, "node/$node->nid", $title_attribs, NULL, NULL, FALSE, FALSE);

This sort of works - but the problem is that it produces stuff like this:

<a href="/drupal-4.7.4/usa/exciting" onMouseover="&quot;ddrivetip(&#039;fixedtipdiv-21&#039;, &#039;400&#039;)" onMouseout="&quot;hideddrivetip()&quot;">A test thingy by USA</a>

As you can see, it's turning all the command stuff into html entities - is there any way around this, other than building the link completely by hand?

Comments

john morahan’s picture

You've got some extra double quotes in there. The l() function adds the double quotes for you, so you don't need to place them inside the attribute value strings. When you do, they get converted. Just remove them.

    $title_attribs['onMouseover'] = 'ddrivetip(\'fixedtipdiv-' . $node->nid . '\', \'400\')';
    $title_attribs['onMouseout'] = 'hideddrivetip()';
    $cell['data'] = l($node->node_title, "node/$node->nid", $title_attribs, NULL, NULL, FALSE, FALSE);
joel_guesclin’s picture

You're right about there being extra double-quotes - however, once I sort that out the single-quotes remaining still get converted so that the single quotes are being displayed as html entities

john morahan’s picture

The attributes get passed to drupal_attributes which filters them through check_plain, so I don't think there's any way around this. Shouldn't stop the javascript from working though.