Reputation: 337
l(t('Edit'), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination())),
I'd like to be able to replace the word "Edit" with an image instead, however when I put an image src in there it shows up as text. Is there a different function I should be using?
I'm using Drupal as my framework.
Thanks ffrom a noob.
Upvotes: 0
Views: 841
Reputation: 193
This is the best way I implemented:
list($nodeImage) = field_get_items('node', $node, 'uc_product_image');
$style_array = array('path' => $nodeImage['uri'], 'style_name' => 'MY_IMAGE_STYLE');
$render_node_image = theme('image_style', $style_array);
$render_node_image_WITH_LINK = l($render_node_image, 'node/' . $node->nid, array('html' => TRUE));
print $render_node_image_WITH_LINK
Upvotes: 0
Reputation: 1723
Best way to do this is to combine l() and theme_image():
print l(theme_image(array('path' => 'edit_button.png', 'attributes' => array('title' => t('Edit')))), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination(), 'html' => TRUE));
You should also use drupal_get_path() to prefix the path of your image. This way you will fully apply to the Drupal Coding standards, and make your life easier.
Upvotes: 2
Reputation: 2181
That button should have its own class, for example, action_button
or an id such as edit_button
. Now use CSS to hide the text and use a background image in its place as shown below:
.action_button, #edit_button {
/* Hide Text */
text-indent: -9999px;
display: block;
background: url('edit_button.png') no-repeat;
/* Set width and height equal to the size of your image */
width: 20px;
height: 20px;
}
EDIT 1:
Change your code with below and use above CSS:
l(t('Edit'), 'node/'.$node->nid.'/webform/components/'.$cid, array('attributes' => array('id' => array('edit_button')), 'query' => drupal_get_destination()));
EDIT 2 [FINAL]:
Passing html
as TRUE
to array parameter
of l()
method can make us able to use first parameter
as img
tag instead of just text for display as link:
l('<img src="edit_button.png" alt="Edit" />', 'node/'.$node->nid.'/webform/components/'.$cid, array('query' => drupal_get_destination(), 'html' => 'TRUE'));
Upvotes: 1